• Block commands from showing up in chat
    5 replies, posted
Basically, when I type anything prefixed by / or ! I don't want it to show up in chat. [IMG]http://i.imgur.com/TvlS1Hq.png[/IMG] 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. [B]Solution by MPan1:[/B] [CODE]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 )[/CODE] Add to lua/autorun/server
Well, you could just use the [URL="https://wiki.garrysmod.com/page/GM/PlayerSay"]PlayerSay hook[/URL],[URL="https://wiki.garrysmod.com/page/string/sub"] string sub[/URL] 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] [CODE] 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 ) [/CODE]
[QUOTE=MPan1;49669220]Well, you could just use the [URL="https://wiki.garrysmod.com/page/GM/PlayerSay"]PlayerSay hook[/URL],[URL="https://wiki.garrysmod.com/page/string/sub"] string sub[/URL] 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] [CODE] 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 ) [/CODE][/QUOTE] 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 : [url]https://github.com/Nayruden/Ulysses/blob/7051b70538080f8bf1238ca1363766369125540e/ulib/lua/ulib/server/concommand.lua[/url] line 68; Replace by [code]return ""[/code]
[QUOTE=Speedy02;49669252]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 ?[/QUOTE] 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.
[QUOTE=MPan1;49669220]Well, you could just use the [URL="https://wiki.garrysmod.com/page/GM/PlayerSay"]PlayerSay hook[/URL],[URL="https://wiki.garrysmod.com/page/string/sub"] string sub[/URL] 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] [CODE] 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 ) [/CODE][/QUOTE] Working perfectly, thanks a lot! I'll add your code to the main post in case anyone googles this same thing.
Sorry, you need to Log In to post a reply to this thread.