ID:159201
 
Suppose you wanted your game to consistently play one of several included music files. When one music file finished, it would randomly pick another music file to play afterwords. Any one except the one it just played, but preferably shuffling all the songs into a random order then playing through all of them each time around.

Of course, the player should also be able to turn this music off and on again any time they want.

How would you go about doing that?
var/CurTrack
var/list/Tracks=list("50"='midi.mid',"60"='midi2.mid')
//50 & 60 being the track lengths in 10th of seconds...
mob/var/MusicOn=1
proc/PlayRandomMusic()
while(world)
for(var/v in Tracks)
CurTrack=Tracks[v]
for(var/mob/M in world) if(M.MusicOn)
M<<sound(null);M<<sound(CurTrack)
sleep(text2num(v))

mob/verb/Toggle_Music()
usr.MusicOn=!usr.MusicOn
if(usr.MusicOn) usr<<sound(CurTrack)
else usr<<sound(null)


Something like that could work. You could sort the list to start with, or even once every time it starts playing.
With the Toggle Music verb, if somebody starts hearing a song in the middle, it will get cut off before the end in order to keep all players hearing the same music. If you didn't care about that then you could just make it a mob/proc.
You may also want to add something on Login() to play the CurTrack, otherwise people won't hear music until the next song starts.