ID:257755
 
//Title: General Sound Playing Procedure
//Credit to: DerDragon
//Contributed by: John Doh
//Dependency of: 3.5 Beta or higher.

/*
This is a procedure that lets you play a sound, and set all
it's variables with it, with one line.

Arguments:
sound = a sound datum or file
listeners = list of people listening
f = frequency (how fast it is) -100 to 100
e = environment
v = volume
c = channel
repeat = 0 if no repeat; 1 if repeat
p = priority
*/


proc/snd_(sound,list/listeners,atom/src,f,e=-1,v,c,repeat,p)
var/sound/S
var/music
if(listeners == "world")
listeners = list()
for(var/mob/M in world)
listeners += M
if(!istype(listeners,/list))
listeners = list(listeners)
if(istype(sound,/sound))
S = sound
else
if(findtext("[sound]",".mid"))
if(!c) c = 1
S = new(sound)
if(p)
S.priority = p
if(c==1)
music = 1
S.priority = 255
for(var/mob/M in listeners)
if(!M.client||(music&&!M.client.music))
listeners.Remove(M)
if(e) S.environment = e
else
if(istype(src))
S.environment = soundenv
if(f) S.frequency = f
if(c) S.channel = c
if(repeat)
S.repeat = 1
else
S.repeat = 0
if(v) switch(v)
if("fadein")
v = 0
S.volume = v
S.status = SOUND_STREAM+SOUND_UPDATE
spawn
while(v<100)
for(var/mob/M in listeners)
if(!M.client||(music&&!M.client.music))
listeners.Remove(M)
v += 2
S.frequency = 1
S.volume = v
listeners << S
sleep(1)
if("fadeout")
v = 100
S.volume = v
S.status = SOUND_STREAM+SOUND_UPDATE
spawn
while(v>0)
for(var/mob/M in listeners)
if(!M.client||(music&&!M.client.music))
listeners.Remove(M)
v -= 2
S.frequency = 1
S.volume = v
listeners << S
sleep(1)
else
S.volume = v
listeners << S
return S