End of round music, with disable function.

How would I make a client command, lets say !nomusic, stop the music playing at end of round, and have the server remember peoples setting through map-changes/restarts. I am a bit of a noob when it comes to lua…


local music = {
	
	"zapper_ttt/Black_Mountains_new.mp3",
	"zapper_ttt/Bullseye_new.mp3",
	"zapper_ttt/Come_And_Get_It_new.mp3",
	"zapper_ttt/Cosmos_new.mp3",
	"zapper_ttt/Declaration_new.mp3",
	"zapper_ttt/Dreams_new.mp3",
	"zapper_ttt/Get_Out_new.mp3",
	"zapper_ttt/Get_Some_new.mp3",
	"zapper_ttt/Lucid_new.mp3",
	"zapper_ttt/I_Just_Want_To_Run_new.mp3",
	
}

for k, v in pairs( music ) do
	resource.AddFile( "sound/"..v )
end

hook.Add( "TTTEndRound", "End Round Music", function( wtype )

	if wtype == WIN_INNOCENT then

		local song = table.Random( music )
		song = "surface.PlaySound(\""..song.."\")"

		BroadcastLua( song )

	elseif wtype == WIN_TRAITOR then

		local song = table.Random( music )
		song = "surface.PlaySound(\""..song.."\")"

		BroadcastLua( song )

	else

		local song = table.Random( music )
		song = "surface.PlaySound(\""..song.."\")"

		BroadcastLua( song )

	end

end )

[editline]28th October 2013[/editline]

Actually, I modified TTT to create a convar tick-box in TTT settings (music_end). How would I make it so that when the client convar “music_end” equals 0, the code to play the music will not run.

[lua]local music = {
“zapper_ttt/Black_Mountains_new.mp3”,
“zapper_ttt/Bullseye_new.mp3”,
“zapper_ttt/Come_And_Get_It_new.mp3”,
“zapper_ttt/Cosmos_new.mp3”,
“zapper_ttt/Declaration_new.mp3”,
“zapper_ttt/Dreams_new.mp3”,
“zapper_ttt/Get_Out_new.mp3”,
“zapper_ttt/Get_Some_new.mp3”,
“zapper_ttt/Lucid_new.mp3”,
“zapper_ttt/I_Just_Want_To_Run_new.mp3”,
}

if SERVER then
for v in pairs( music ) do resource.AddFile( “sound/” … v ) end

util.AddNetworkString "TTTPlayEndRoundMusic"

hook.Add( "TTTEndRound", "End Round Music", function( wtype )
    net.Start("TTTPlayEndRoundMusic")
    net.WriteUInt(math.random(#music), 8)
    net.Broadcast()
end )

elseif CLIENT then
net.Receive(“TTTPlayEndRoundMusic”, function()
if cookie.GetNumber(“TTTPlayMusic”, 1) == 0 then return end

    local song = music[net.ReadUInt(8)]
    surface.PlaySound(song)
end)

concommand.Add("DisableTTTMusic", function()
    cookie.Set("TTTPlayMusic", 0)
end)

end[/lua]

replace cookie with simple convar check if y’want.

You can also bind ‘stopsound’ to a key. It’s a useful tool to have regardless.