Block commands from showing up in chat

Basically, when I type anything prefixed by / or ! I don’t want it to show up in chat.

I’m aware that you can set the individual command to be hidden in the ULX files, but when you have a lot of commands that’s a ton of work.

I’d rather everything which starts with a / or a ! is completely blocked from the chat.

Not trying to ask anyone to code for me, I know it might sound like that. Could just use a few tips on how I can achieve this. Thanks.

Solution by MPan1:


hook.Add( "PlayerSay", "DontShowStuff", function( ply, text, team )
	local firstchar = string.sub( text, 1, 1 ) -- this gets the first character of the text typed, e.g. !
	if ( firstchar == "!" ) or ( firstchar == '/' ) then -- if the first character is ! or / then
		return '' -- this makes the text not get printed in the chat
	end
end )

Add to lua/autorun/server

Well, you could just use the PlayerSay hook,string sub the first character, check if it’s a ‘!’ or a ‘/’, and if it is, return a blank string. I’ll post an example soon

[editline]4th February 2016[/editline]



hook.Add( "PlayerSay", "DontShowStuff", function( ply, text, team )
	local firstchar = string.sub( text, 1, 1 ) -- this gets the first character of the text typed, e.g. !
	if ( firstchar == "!" ) or ( firstchar == '/' ) then -- if the first character is ! or / then
		return '' -- this makes the text not get printed in the chat
	end
end )


I wonder how do you know if this hook will be called before the ulx’s hook ?
If you return an empty string, it will stop this from being called in any other hooks, so ulx won’t like that ? Am I wrong ?

You could :
https://github.com/Nayruden/Ulysses/blob/7051b70538080f8bf1238ca1363766369125540e/ulib/lua/ulib/server/concommand.lua line 68;
Replace by


return ""

Well, I don’t know if it would be called before the ULX hook, I’m just saying that as a general thing (although you’re right, it might not work with ULX, but it works in vanilla gmod)

Ehh I’ll just drop this here:
I did this exact thing (placed the code in lua/autorun/server) and ulx commands still do work.

Working perfectly, thanks a lot! I’ll add your code to the main post in case anyone googles this same thing.