-- LUA Script - precede every function and global member with lowercase name of script + '_main' jukeboxes = {} local function GetArgs( str, sep ) local sep = sep or ',' local pos = 1 local list = {} local length = #str while pos < length + 1 do local nextPos = find( str, sep, pos + 1 ) or length if nextPos < length then list[ #list + 1 ] = sub( str, pos, nextPos - 1 ) else list[ #list + 1 ] = sub( str, pos, nextPos ) break end pos = nextPos + 1 end return list end function jukebox_init_name( e, name ) jukeboxes[ e ] = { state = 'init', name = name } end function jukebox_main( e ) local jb = jukeboxes[ e ] if jb == niul then return end if jb.state == 'init then local Args = GetArgs( jb.name ) jb.tunes = {} for i = 2, #Args do jb.tunes[ #jb.tunes + 1 ] = tonumber( Args[ i ] ) end jb.currentTune = 1 jb.state = 'play' elseif jb.state == 'play' then jb.timer = g_Time + jb.tunes[ jb.currentTune ] * 1000 PlaySound( e, jb.currentTune - 1 ) jb.state == 'wait' elseif jb.state == 'wait' then if g_Time > jb.timer then jb.currentTune = jb.currentTune + 1 if jb.currentTune > #jb.tunes then jb.currentTune = 1 end jb.state = 'play' end end end end