• Help with round end music.
    6 replies, posted
So, what I want is a script that will select a random song from a list of 10 at round end. I'm new to coding and this is what i've got so far. Why it no work D: [CODE]-- You can add up to 3 sounds for this. Add or delete resource.addfile as you need resource.AddFile("sound/getlow.mp3") resource.AddFile("sound/ScaryMonstersNiceSprites.mp3") resource.AddFile("sound/yourmusic.whatever") local song = math.random(1,2) -- Remember to change the name of the sounds to the sound you want from above local function PlayMusic(wintype) if wintype == WIN_INNOCENT then if song == 1 then BroadcastLua('surface.PlaySound("getlow.mp3")') elseif song == 2 then BroadcastLua('surface.PlaySound("ScaryMonstersNiceSprites.mp3")') end[/CODE] Yes, I know there are only two songs for now, but any reason this isn't working? EDIT: Seems it chooses the same song every map? And it goes to a new song every map change, how do I fix this?
The TTT End Round Hook is server-side. You'll need to network the server data to the client-side. Here's the one I give out: [url]https://dl.dropboxusercontent.com/u/26074909/ttt_end_round.rar[/url] Feel free to learn from it, or use it.
Where exactly do I put the sound files that the lua code will run?
[QUOTE=Zaeron;41701437]Where exactly do I put the sound files that the lua code will run?[/QUOTE] garrysmod/sound
[LUA] -- You can add up to 3 sounds for this. Add or delete resource.addfile as you need resource.AddFile("sound/1.mp3") resource.AddFile("sound/2.mp3") resource.AddFile("sound/3.mp3") -- Remember to change the name of the sounds to the sound you want from above local function PlayMusic(wintype) if wintype == WIN_INNOCENT then BroadcastLua('surface.PlaySound(""..math.random(3)..".mp3")') end [/LUA] Rename all the songs to numbers and then try that ^. The 3 is the highest number that it picks at random. So it will pick 1.mp3, 2.mp3 or 3.mp3. If you wanted to do one for traitors but with different sounds then: [LUA] -- You can add up to 3 sounds for this. Add or delete resource.addfile as you need resource.AddFile("sound/t1.mp3") resource.AddFile("sound/t2.mp3") resource.AddFile("sound/t3.mp3") -- Remember to change the name of the sounds to the sound you want from above local function PlayMusic(wintype) if wintype == WIN_TRAITOR then BroadcastLua('surface.PlaySound("t"..math.random(3)..".mp3")') end [/LUA] Same thing but there is a t before the number on these ones and it will only do songs with T in them. If you want me to explain it more simple then please tell me. I'm horrible at explaining
[QUOTE=The Android1;41702592]garrysmod/sound[/QUOTE] Umm, if this is the main directory then I don't have a sound folder in my garrysmod folder. Should I just create a sound folder?
[QUOTE=Zaeron;41702736]Umm, if this is the main directory then I don't have a sound folder in my garrysmod folder. Should I just create a sound folder?[/QUOTE] You should have one. You should have one for both server and client. So if it was a traitorwin.wav then: C:\Program Files\Steam\SteamApps\Arken\GarrysMod\GarrysMod\sound\trizone\traitorwin.wav and for server: C:\srcds\garrysmod\sound\trizone\traitorwin.wav In the lua you would then put: surface.PlaySound("trizone/traitorwin.mp3") Obviously it can't be trizone/ you will need to put your server name so if your server is awesomeserver then awesomeserver/traitorwin.mp3. Do not put Trizone. Thats my server :) [editline]4th August 2013[/editline] If you don't have one then yes, make one
Sorry, you need to Log In to post a reply to this thread.