Type '!stopsound' in Chat to Stop End of Round Music

Did some researchand am trying to get a custom command that allows users to stop the end of the round music if it gets anoying. However nothing happens. No lua errors though so that’s good lol.


// if 'stopsound' is entered into the chat any music will be stopped
function stopsoundCommand( ply, text, public )
    if (string.sub(text, 1, 10) == "!stopsound") then
        RunConsoleCommand("stopsound")
        return(false)
    end
end
hook.Add( "PlayerSay", "stopsoundCommand", stopsoundCommand );

I think that you are executing the command on the server. Do ply:ConCommand(“stopsound”).
And remove brackets from return(false) so it’s like this: “return false”.

I’ll test it and get back to you.

Thanks.

Will that work even if sv_cheats is off?

It’s not working:


FCVAR_SERVER_CAN_EXECUTE prevented server running command: stopsound


Code:


function stopsoundCommand( ply, text, public )
    if (string.sub(text, 1, 4) == "test") then
        chat.AddText("This test has worked!")
    end
    if (string.sub(text, 1, 10) == "!stopsound") then
        //RunConsoleCommand("stopsound")
        ply:ConCommand("stopsound")
        return false
    end
end
hook.Add( "PlayerSay", "stopsoundCommand", stopsoundCommand );

Looks like it does require sv_cheats 1

[editline]2nd June 2013[/editline]

Try this:



function stopsoundCommand( ply, text, public )
    if (string.sub(text, 1, 4) == "test") then
        chat.AddText("This test has worked!")
    end
    if (string.sub(text, 1, 10) == "!stopsound") then
        //RunConsoleCommand("stopsound")
        ply:SendLua("LocalPlayer():ConCommand('stopsounds')")
        return false
    end
end
hook.Add( "PlayerSay", "stopsoundCommand", stopsoundCommand );


I’ll check it out and get back to you.

Thanks.

No need for LocalPlayer(), and it’s ‘stopsound’, not ‘stopsounds’.

[lua]function stopsoundCommand( ply, text, public )
if (string.sub(text, 1, 4) == “test”) then
chat.AddText(“This test has worked!”)
end
if (string.sub(text, 1, 10) == “!stopsound”) then
ply:SendLua(“RunConsoleCommand(‘stopsound’)”)
return false
end
end
hook.Add( “PlayerSay”, “stopsoundCommand”, stopsoundCommand );[/lua]

Thanks for the corrections, usermessage hooks can be used apparently as well.

Sonyfuzion’s code works just fine.

Thanks!