• Functions to 'play sounds'
    6 replies, posted
Hi guys I have a round system, with this round system I have a function thats gets called upon when the round ends. 'function round.end()' I want to play music or a sound when this function is called upon. Does anyone have any idea's to how I go about this. I have been on Gmod.wiki for hours and looked around on youtube but no luck. Any help is greatly appreciated. Here is my code atm. function round.end() round.Broadcast("The round is over!") round.Broadcast( "The next round is in" .. round.Break .. "seconds!" end
[lua]function round.end() local sound = "insert round end sound here" BroadcastLua("surface.PlaySound('"..sound.."')") round.Broadcast("The round is over!") round.Broadcast( "The next round is in" .. round.Break .. "seconds!") end[/lua]
See people always say this, but how do you exactly do this? In the Broadcast. DO you put a full directory or what? Then is the local sound to do you put the pull directory or just the name of the sound? I can't get it to work I get the error. attempt to index global 'game over' (a nil value) "gameover is the name of the sound I want to play" If you could show me directly how you would do it. I would be most grateful. I have been trying to do this for like 2 months now and no one has a straight answer. :P
It's relative to the [B]sound[/B] directory, [url=http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index8f77.html]or you can just use an HL2 sound.[/url] [lua]function round.end() local sound = "vo/Streetwar/nexus/ba_headforroof.wav" BroadcastLua("surface.PlaySound('"..sound.."')") round.Broadcast("The round is over!") round.Broadcast( "The next round is in" .. round.Break .. "seconds!") end[/lua]
So why is the ..sound.. there? What is the purpose of it? OH is that using the local variable that was created above and telling it to play it?
Yes. The only part you should be modifying is the sound variable at the top.
Ah I see now!! Thanks a lot ^^
Sorry, you need to Log In to post a reply to this thread.