ID:1671968
 
(See the best response by Nadrew.)
I'm trying to create a proc or something that will play a random sound at intervals while on a certain map but I can't seem to figure out how. I'm trying to get wind blowing or birds chirping while outside.
usr()<<sound('birds.wav')


Something like that but a way to project to only the the person hearing it, though I'm not sure if I should use src instead.

Best response
There's a few methods you could use to do this, depending on how you want it done. If it's just a per-person thing you could probably handle it on the mob-level instead of on a larger scale -- which is what you'd do if you wanted everyone to hear the same thing at the same time.

mob/var
list/random_sounds
tmp/sound_delay = 100 // 10 seconds.

mob/proc/SoundLoop()
while(random_sounds)
var/picked_sound = pick(random_sounds)
if(picked_sound) src << sound(picked_sound)
sleep(sound_delay)

area
random_sounds
var/list/sounds

Entered(mob/M)
if(ismob(M) && M.client)
if(sounds)
M.random_sounds = sounds // No need to copy the list, just set to a direct reference
M.SoundLoop()
return ..()

Exited(mob/M)
if(ismob(M) && M.client)
M.random_sounds = null // This will kill the loop.
return ..()

Forest
sounds = list('birds.wav','wind.wav')


This is purely an example written on the fly, of course. There are definitely improvements to be made, and I'm sure it could be made more efficient as well. This should give you an idea of where you should start though.
Thank you! Also how could I create one simple line that plays random sounds to the view?

I tried
view()<<sound('punchhit1.wav','punchhit2.wav')

but that didn't work, it always plays the first sound.
You'd have to make it pick from a list, passing extra arguments to sound() isn't gonna do much besides mess things up.

view() << pick(list('punchhit1.wav','punchhit2.wav'))


I also recommend converting those wav files to ogg or similar formats, it will greatly decrease the resource download for your game.
Thanks! I'll take this as a learning experience, I just always used wav since they were easy to edit on Audacity, but I'll go ahead and convert them once I'm certain I will be using them.