Advertisement
LucianDevran

Gmod Roundend Music Addon

Jun 25th, 2018
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.16 KB | None | 0 0
  1. So I "created" or better enhanced and adjusted an addon to my personal needs. It´s an addon which plays music at the end of an round depending on the result (who won). But I found it kinda frustrating since my friends were complaining that the music was either too loud or too silent  and I adjusted every single song of about 90 or so by hand and they kept complaining. Someone then pointed out that an Interface or just a command or option to adjust the volume would be really nice but I couldn't get my head through anything that would do that.
  2.  
  3.  
  4. EDIT:
  5.  
  6. So I used the "surface.PlaySound ( _sound)  function (in which ( _sound ) is a string as a Random Table depending on the win event.
  7. There was no real way to le the client adjust the volume.
  8. I then found that I could use another "function" to do that but im not sure how to change the code to work with the random table i have..
  9.  
  10. So what i had before was this:
  11.  
  12.  
  13. net.Receive( "_ttt_end_round_music", function( byte, Player )
  14.    local _sound = net.ReadString( );
  15.    surface.PlaySound( _sound );
  16. end )
  17.  
  18.  
  19. And now I found this :
  20.  
  21.  
  22. local sound = CreateSound( LocalPlayer(), fileName )
  23. sound:PlayEx( volume_0_to_1, pitch_0_to_255 )
  24.  
  25.  
  26. What i would now do is this:
  27.  
  28.  
  29. net.Receive( "_ttt_end_round_music", function( byte, Player )
  30.    local _sound = net.ReadString( );
  31.    sound.Play( _sound,)
  32. end )
  33.  
  34.  
  35. But I'm almost 100% sure this wont work and also I would want it so the client could do something to adjust the volume.
  36. Like a function that calls at the same hook as the play.sound which would bring up a slider to adjust the Volume
  37.  
  38. Edit2:
  39.  
  40. I talked to some Dont Starve coder and they came up with this:
  41.  
  42.  
  43. net.Receive( "_ttt_end_round_music", function( byte, Player )
  44.     local _sound = net.ReadString( );
  45.     local _audio = CreateSound(Player, _sound)
  46.     _audio:PlayEx( volume_0_to_1, pitch_0_to_255 )
  47. end )
  48.  
  49. But this gives me this error:
  50.  
  51.  
  52. [TTT Round Ending Music] lua/autorun/client/cl_end_round_music.lua:3: Tried to use a NULL entity!
  53.   1. CreateSound - [C]:-1
  54.    2. func - lua/autorun/client/cl_end_round_music.lua:3
  55.     3. unknown - lua/includes/extensions/net.lua:32
  56.  
  57.  
  58. Serversided code:
  59.  
  60.  
  61. END_OF_ROUND_WIN_DEFAULT_SOUND = "round/sound37.mp3";
  62.  
  63. if ( SERVER ) then
  64.     util.AddNetworkString( "_ttt_end_round_music" );
  65.    
  66.     for k, v in pairs( END_OF_ROUND_WIN_INNOCENT_SOUNDS ) do resource.AddFile( "sound/" .. v ); end
  67.     for k, v in pairs( END_OF_ROUND_WIN_TRAITOR_SOUNDS ) do resource.AddFile( "sound/" .. v ); end
  68.     for k, v in pairs( END_OF_ROUND_WIN_TIMELIMIT_SOUNDS ) do resource.AddFile( "sound/" .. v ); end
  69.    
  70.     local function endofround( wintype )
  71.         // Default sound
  72.         local _sound = END_OF_ROUND_WIN_DEFAULT_SOUND
  73.        
  74.         if wintype == WIN_INNOCENT then
  75.             _sound = table.Random( END_OF_ROUND_WIN_INNOCENT_SOUNDS );
  76.         elseif wintype == WIN_TRAITOR then
  77.             _sound = table.Random( END_OF_ROUND_WIN_TRAITOR_SOUNDS );
  78.         elseif wintype == WIN_TIMELIMIT then
  79.             _sound = table.Random( END_OF_ROUND_WIN_TIMELIMIT_SOUNDS );
  80.         end
  81.        
  82.         net.Start( "_ttt_end_round_music" );
  83.             net.WriteString( _sound );
  84.         net.Broadcast( );
  85.     end
  86.     hook.Add( "TTTEndRound", "Handymanendofround", endofround )
  87. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement