So.. I re-wrote one of the "RoundEndMusic" addons out there to get a menu in F1 to disable the music.
Now, in the original addon, the music gets played with "surface:PlaySound". That did work nicely, but I could'nt change volume/pitch (which will be configurable for each player).
So now I use sound:PlayEx because i can use volume and pitch there.. but there is a problem.
So, after the round, the music does start playing, but randomly after a certain time, it just stops. I get no message in console or any errors.. I also never stop the sound myself, that should only happen when the new round starts.
Here is the main part of the code:
local function endofround_music( wintype )
// Default sound
timer.Simple(1, function()
//if not PlayMusic:GetBool() then return end
wintype = wintypeglobal
local _sound = CreateSound(LocalPlayer(), END_OF_ROUND_WIN_DEFAULT_SOUND)
chat.AddText( wintype )
if wintype == "3" then
chat.AddText( "3" )
_sound = CreateSound(LocalPlayer(), table.Random( END_OF_ROUND_WIN_INNOCENT_SOUNDS ))
elseif wintype == "2" then
chat.AddText( "2" )
_sound = CreateSound(LocalPlayer(), table.Random( END_OF_ROUND_WIN_TRAITOR_SOUNDS ))
elseif wintype == "4" then
_sound = CreateSound(LocalPlayer(), table.Random( END_OF_ROUND_WIN_TIMELIMIT_SOUNDS ))
end
//_sound:PlayEx(0.1, 100)
_sound:Play()
end)
end
hook.Add( "TTTEndRound", "endofround_music", endofround_music )
I think the _sound object gets out of scope and then stopped and deleted. Your code doesn't look very elegant in general ether.
This is not my original code. I just recoded it a bit. I will structure it more.
If it gets out of scope, is there anything I can do? I mean, for now I just made the sounds quieter with an external program.
Sorry, you need to Log In to post a reply to this thread.