• Need Help With Sound Player
    16 replies, posted
Hey, I want to have music constantly running on my server, but i don't know how. Could someone create a lua file that plays all the sounds in sounds/music/killingtime Each one after another, but once all the files have been played, it plays them again?
EDIT: [lua]local songs = file.Find("sounds/music/killingtime/*.mp3") //change to .wav if its a .wav Gets a list of the songs[/lua]
I'm pretty sure you could do something like this [lua] local songs = file.Find( "sounds/music/killingtime/*.mp3" ) RunConsoleCommand( "play", songs ) [/lua] Untested but the idea is there, right?
[QUOTE=devinpro;29520353]EDIT: [lua]local songs = file.Find("sounds/music/killingtime/*.mp3") //change to .wav if its a .wav Gets a list of the songs[/lua][/QUOTE] You have to give file.Find true as second argument. [editline]30th April 2011[/editline] [QUOTE=Quark:;29520908]I'm pretty sure you could do something like this [lua] local songs = file.Find( "sounds/music/killingtime/*.mp3" ) RunConsoleCommand( "play", songs ) [/lua] Untested but the idea is there, right?[/QUOTE] You cannot play a table.
hmm, ok, so the first one finds the files, so now how do we play them? could you do: RunConsoleCommand( "play", "sounds/music/killingtime/*.wav")
[QUOTE=blackfire88;29535946]hmm, ok, so the first one finds the files, so now how do we play them? could you do: RunConsoleCommand( "play", "sounds/music/killingtime/*.wav")[/QUOTE] without sounds. play is relative to sounds folder, meaning you jsut have to do "play","music/killingtime/<songname>.wav")
[QUOTE=Amic;29544243]without sounds. play is relative to sounds folder, meaning you jsut have to do "play","music/killingtime/<songname>.wav")[/QUOTE] Or you could use local RealDirectory = string.sub(songs[1],"sounds/","") "play", RealDirectory
[QUOTE=Zoey Artyom;29567787]Or you could use local RealDirectory = string.sub(songs[1],"sounds/","") "play", RealDirectory[/QUOTE] Yeah, but what for. What if i have like sounds/entity/sounde/engine.wav. It would break it.
[lua]local files = file.Find("../sound/music/killingtime/*.mp3") local playing = false local playingID = 0 hook.Add("Think", "KillingTimeMusic", function() if(playing == false) then playingID = ((playingID + 1) % #files) + 1 local file = "music/killingtime/"..files[playingID] local length = SoundDuration(files) surface.PlaySound(file) timer.Simple(length, function() playing = false end) end end)[/lua] Untested, looks like it should work though.
sound's great, i'll test it! see the pun? Sound's great... I'm hopeless. also, one more thing. I want it to be so that if someone types !stopmusic the current song stops for them only. so clientside (probably another lua file) [editline]3rd May 2011[/editline] Unknown command "local" Unknown command "local" Unknown command "local" Unknown command "hook.Add" Unknown command "if" Unknown command "playingID" Unknown command "local" Unknown command "local" Unknown command "surface.PlaySound" Unknown command "timer.Simple" Unknown command "end" Unknown command "end" [editline]3rd May 2011[/editline] [QUOTE=GranPC;29570386][lua]local files = file.Find("../sound/music/killingtime/*.mp3") local playing = false local playingID = 0 hook.Add("Think", "KillingTimeMusic", function() if(playing == false) then playingID = ((playingID + 1) % #files) + 1 local file = "music/killingtime/"..files[playingID] local length = SoundDuration(files) surface.PlaySound(file) timer.Simple(length, function() playing = false end) end end)[/lua] Untested, looks like it should work though.[/QUOTE] Unknown command "local" Unknown command "local" Unknown command "local" Unknown command "hook.Add" Unknown command "if" Unknown command "playingID" Unknown command "local" Unknown command "local" Unknown command "surface.PlaySound" Unknown command "timer.Simple" Unknown command "end" Unknown command "end"
You have to put it in a .lua file and run it with lua_openscript_cl.
Unknown command "lua_openscript_cl"
Are you even in garrys mod are you are trying to do this in another source game?
:doh:
[QUOTE=blackfire88;29608125]Unknown command "lua_openscript_cl"[/QUOTE] lua_openscript_cl <What you are opening here> EDIT: in the console, incase you didn't know..
[QUOTE=beasty;29611407]lua_openscript_cl <What you are opening here>[/QUOTE] How is this helpful? if you just put lua_openscript_cl it wont give you error an unknown command error
yes this is garry's mod.and yes i did it in console. [editline]6th May 2011[/editline] maybe if i put it in the autorun/server folder?
Sorry, you need to Log In to post a reply to this thread.