Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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.
- EDIT:
- So I used the "surface.PlaySound ( _sound) function (in which ( _sound ) is a string as a Random Table depending on the win event.
- There was no real way to le the client adjust the volume.
- 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..
- So what i had before was this:
- net.Receive( "_ttt_end_round_music", function( byte, Player )
- local _sound = net.ReadString( );
- surface.PlaySound( _sound );
- end )
- And now I found this :
- local sound = CreateSound( LocalPlayer(), fileName )
- sound:PlayEx( volume_0_to_1, pitch_0_to_255 )
- What i would now do is this:
- net.Receive( "_ttt_end_round_music", function( byte, Player )
- local _sound = net.ReadString( );
- sound.Play( _sound,)
- end )
- 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.
- Like a function that calls at the same hook as the play.sound which would bring up a slider to adjust the Volume
- Edit2:
- I talked to some Dont Starve coder and they came up with this:
- net.Receive( "_ttt_end_round_music", function( byte, Player )
- local _sound = net.ReadString( );
- local _audio = CreateSound(Player, _sound)
- _audio:PlayEx( volume_0_to_1, pitch_0_to_255 )
- end )
- But this gives me this error:
- [TTT Round Ending Music] lua/autorun/client/cl_end_round_music.lua:3: Tried to use a NULL entity!
- 1. CreateSound - [C]:-1
- 2. func - lua/autorun/client/cl_end_round_music.lua:3
- 3. unknown - lua/includes/extensions/net.lua:32
- Serversided code:
- END_OF_ROUND_WIN_DEFAULT_SOUND = "round/sound37.mp3";
- if ( SERVER ) then
- util.AddNetworkString( "_ttt_end_round_music" );
- for k, v in pairs( END_OF_ROUND_WIN_INNOCENT_SOUNDS ) do resource.AddFile( "sound/" .. v ); end
- for k, v in pairs( END_OF_ROUND_WIN_TRAITOR_SOUNDS ) do resource.AddFile( "sound/" .. v ); end
- for k, v in pairs( END_OF_ROUND_WIN_TIMELIMIT_SOUNDS ) do resource.AddFile( "sound/" .. v ); end
- local function endofround( wintype )
- // Default sound
- local _sound = END_OF_ROUND_WIN_DEFAULT_SOUND
- if wintype == WIN_INNOCENT then
- _sound = table.Random( END_OF_ROUND_WIN_INNOCENT_SOUNDS );
- elseif wintype == WIN_TRAITOR then
- _sound = table.Random( END_OF_ROUND_WIN_TRAITOR_SOUNDS );
- elseif wintype == WIN_TIMELIMIT then
- _sound = table.Random( END_OF_ROUND_WIN_TIMELIMIT_SOUNDS );
- end
- net.Start( "_ttt_end_round_music" );
- net.WriteString( _sound );
- net.Broadcast( );
- end
- hook.Add( "TTTEndRound", "Handymanendofround", endofround )
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement