F4 stopsound command for users

Ok so on the ttt server that i play on, there are a lot of songs and sounds being played and it can be offputting and stop you from hearing important things so i want to include a feature to allow players to use the “stopsound” command by pressing F4. This is what i have at the moment, but it doesn’t do the job, anyone point me in the right direction?

[LUA]
function StopAllSound(ply, key)
if key == KEY_F4 then
ply:RunConsoleCommand(“stopsound”)
end
end
hook.Add( “KeyPress”, “KeyPressedHook”, StopAllSound )
[/LUA]

I haven’t programmed in Glua for a long time, but as far as I remember, this should work.

[lua]
function GM:ShowSpare2( ply ) – Default is F4

ply:ConCommand( "stopsound" )

end
[/lua]

That won’t work because stopsound is clientside and its a console command. You can use GM:ShowSpare2 but you need to have a net message that sends the command to the client.


function GM:ShowSpare2( ply )
	ply:SendLua([[RunConsoleCommand("stopsound")]])
end


Should do the trick.

Great this worked :slight_smile: