End of Round music.

Hey guys!

Ive been trying my hardest for a long time now to get end of round music to my TTT server.
Ive tried numerous addons, from the workshop/other websites and the only one ive found that works is this one:

Now ive put all the EndofRoundMusic.lua in the lua/autorun/ folder. And my sounds ive made a seperate folder in the garrysmod folder named ‘sound’ and placed my mp3’s in there.

Heres my code in the EndofRoundMusic.lua:


-- You can add up to 3 sounds for this. Add or delete resource.addfile as you need
resource.AddFile("sound/baggytrousers.mp3")
resource.AddFile("sound/bounce.mp3")
resource.AddFile("sound/britishanthem.mp3")
resource.AddFile("sound/elevator.mp3")
resource.AddFile("sound/glitchhop.mp3")
resource.AddFile("sound/hotlinemiami.mp3")
resource.AddFile("sound/kingdonhearts.mp3")
resource.AddFile("sound/portal.mp3")
resource.AddFile("sound/sandblast.mp3")


local function PlayMusic(wintype)
   if wintype == WIN_INNOCENT then
      BroadcastLua('surface.PlaySound("baggytrousers.mp3")')
	  
   elseif wintype == WIN_INNOCENT then
	  BroadcastLua('surface.PlaySound("bounce.mp3")')
	  
   elseif wintype == WIN_INNOCENT then
	  BroadcastLua('surface.PlaySound("britishanthem.mp3")')
	 
   elseif wintype == WIN_INNOCENT then
	  BroadcastLua('surface.PlaySound("sandblast.mp3")')
   
   elseif wintype == WIN_TRAITOR then
          BroadcastLua('surface.PlaySound("glitchhop.mp3")')
	  
   elseif wintype == WIN_TRAITOR then
	  BroadcastLua('surface.PlaySound("hotlinemiami.mp3")')
	  
   elseif wintype == WIN_TRAITOR then
	  BroadcastLua('surface.PlaySound("kingdonhearts.mp3")')
	  
   elseif wintype == WIN_TRAITOR then
	  BroadcastLua('surface.PlaySound("portal.mp3")')

   elseif wintype == WIN_TIMELIMIT then
      BroadcastLua('surface.PlaySound("elevator.mp3")')
   end
end
hook.Add("TTTEndRound", "MyMusic", PlayMusic)


Now i know it says at the top ‘-- You can add up to 3 sounds for this. Add or delete resource.addfile as you need’
But im desperate by now, and i would love to make it so it plays all the sounds randomly.

Can anybody give my any suggestions? I literally don’t know what else to do. Thankyou.

Your issue here is that an “if” statement breaks from the code once the condition is met, so, if the innocents win, the first “if” will be called each time. If the Traitors win, the 5th “if”, or “elseif” will be called.

Acecool made a really nice little script for random end round music once, let me see if I can find it for you.

EDIT: https://dl.dropboxusercontent.com/u/26074909/ttt_end_round.rar

There you go, all credits to Acecool of course.

Hiya! thankyou for the reply!

The dropbox link doesnt work? just get a error 404 page. do i need to be logged into it? :slight_smile:

Also i read about the if statement before, i added a code like this to the lua file, but then it just didnt play any music at all!


local soundTable = {Inno={"baggytrousers.mp3", "bounce.mp3", "britishanthem.mp3", "glitchhop.mp3"},
 Trait={"hotlinemiami.mp3", "kingdonhearts.mp3", "portal.mp3", "sandblast.mp3"},
 Time={"elevator.mp3"}}

local function PlayMusic(wintype)
   if wintype == WIN_INNOCENT then
      BroadcastLua('surface.PlaySound("'..table.Random(soundTable[Inno])..'")')
   elseif wintype == WIN_TRAITOR then
      BroadcastLua('surface.PlaySound("'..table.Random(soundTable[Trait])..'")')
   elseif wintype == WIN_TIMELIMIT then
      BroadcastLua('surface.PlaySound("'..table.Random(soundTable[Time])..'")')
   end
end
hook.Add("TTTEndRound", "MyMusic", PlayMusic)

Can you check your console for any missing sound files after it is supposed to play?

Hey, Yeah with the original code (in the original post) I do not get any errors in the console, likewise if i put the code sound table code in instead.

I used to get errors with other addons, this one is the only one that seems to not create any errors. Which i thought was very odd, i expected errors when i put the soundtable code in but didnt get any when it didnt play the music!

EDIT:

I Just re-checked the console with the Sound table code in the LUA and it printed the error
Failed to load sound “”, file probably missing from disk/repository

However i dont get this error with the original code (in the top post). :slight_smile:

Make sure you are still adding the sounds as resources, and make sure you are changing the sounds in the configuration table (soundTable) to the ones you have.

Heya!
Ive double triple checked this!

This is how the code looks atm!


-- You can add up to 3 sounds for this. Add or delete resource.addfile as you need
resource.AddFile("sound/baggytrousers.mp3")
resource.AddFile("sound/bounce.mp3")
resource.AddFile("sound/britishanthem.mp3")
resource.AddFile("sound/elevator.mp3")
resource.AddFile("sound/glitchhop.mp3")
resource.AddFile("sound/hotlinemiami.mp3")
resource.AddFile("sound/kingdonhearts.mp3")
resource.AddFile("sound/portal.mp3")
resource.AddFile("sound/sandblast.mp3")


local soundTable = {Inno={"baggytrousers.mp3", "bounce.mp3", "britishanthem.mp3", "glitchhop.mp3"}, Trait={"hotlinemiami.mp3", "kingdonhearts.mp3", "portal.mp3", "sandblast.mp3"}, Time={"elevator.mp3"}}

local function PlayMusic(wintype)
   if wintype == WIN_INNOCENT then
      BroadcastLua('surface.PlaySound("'..table.Random(soundTable[Inno])..'")')
   elseif wintype == WIN_TRAITOR then
      BroadcastLua('surface.PlaySound("'..table.Random(soundTable[Trait])..'")')
   elseif wintype == WIN_TIMELIMIT then
      BroadcastLua('surface.PlaySound("'..table.Random(soundTable[Time])..'")')
   end
end
hook.Add("TTTEndRound", "MyMusic", PlayMusic)


[editline]10th May 2015[/editline]

Bump? Sorry i really would love some help on this, as ive been coming back to this addon on and off for like a month and its one of those things i cant really find much info on the internet. nobody has made any thorough tutorials and i feel like it should be working but its not! D:

You’re using simple-string names as the key ( table.x / table[ “x” ] ) yet you’re trying to use a variable to reference ( table[ x ] ) which parses Inno / Trait / Time as nil…

Another issue is you’re using BroadcastLua, I’d recommend networking the song and be done with it… I’d also recommend switching from ’ or " to [[ and ]]…

Here’s an old one I wrote: https://dl.dropboxusercontent.com/u/26074909/tutoring/_zipped_code/acecool_ttt_end_round.rar

and with a few sounds to show how to place them: https://dl.dropboxusercontent.com/u/26074909/tutoring/_zipped_code/acecool_ttt_end_round_music.rar

And a few tuts on tables, function naming ( because everything in Lua is stored in some table ), strings, etc… which should help you better understand where it went wrong.

https://dl.dropboxusercontent.com/u/26074909/tutoring/tables/quick_intro_to_tables.lua.html
https://dl.dropboxusercontent.com/u/26074909/tutoring/functions/function_naming.lua.html
https://dl.dropboxusercontent.com/u/26074909/tutoring/strings/string_concatenation.lua.html

Thankyou so much ace!
This is incredibly helpful! :smiley: