I keep trying to make a table that has a simple timer with it that will play random ambient noises every so often. However I can't seem to get it to work, any ideas?
local t = {
"sound1.wav",
"sound2.wav"
}
surface.PlaySound( t[ math.random( 1, #t ) ] )
Or use function of choice.
Depends whether you want it clientside or serverside.
Clientside, Robotboy's code will work if you attach it with a timer (which I assume you know how to actually do so and I know that's what he assumes, but I include one anyway just so you can compare),
[lua]local ambience = {
"sound1.wav",
"sound2.wav"
};
local ambience_delay = 60;
local ambience_repeat = 0; -- 0 is infinite
timer.Create("ambience_player", ambience_delay, ambience_repeat, function()
surface.PlaySound(ambience[math.random(1, #ambience)]);
end);[/lua]
Otherwise serverside you can use:
[url]http://wiki.garrysmod.com/page/Entity/EmitSound[/url]
If you're making an entity make the sounds.
Thanks Nookyava, I was forgetting the delay and repeat.
Sorry, you need to Log In to post a reply to this thread.