• Cyrillic letters blocker
    12 replies, posted
Hello, I'm playing at a [Open Aura] HL2RP server, and it seems like too many Cyrillic (Russian) letters makes the server extremely laggy. So I wounder if it's any way I can block people from using Cyrillic letters in the chat? Thank you in advance Gurrazor
I hardly ever touch strings, but maybe this? [lua] hook.Add ( "PlayerSay", "Cyrillic", function ( ply, text, publicchat ) local bannedletters = { a, b, z, c } for k, v in pairs ( bannedletters ) do if string.find(string.lower( text ), v ) >= 0 then return "" end end end) [/lua]
[lua] string.gsub("Herp derp text", "[^%w%p%s]", "") [/lua] That will give you a string that has all non-AlphaNumeric characters removed.
[QUOTE=PortalGod;26491110][lua] string.gsub("Herp derp text", "[^%w%p%s]", "") [/lua] That will give you a string that has all non-AlphaNumeric characters removed.[/QUOTE] with that, it should look like this [lua] hook.Add ( "PlayerSay", "Cyrillic", function ( ply, text, publicchat ) local newtext = string.gsub( text , "[^%w%p%s]", "") if text != newtext then return newtext end end) [/lua]
That if statement is unnecessary, just return the string after you use gsub on it. If none of the text got filtered, it will return the original text.
[QUOTE=PortalGod;26491671]That if statement is unnecessary, just return the string after you use gsub on it. If none of the text got filtered, it will return the original text.[/QUOTE] from the wiki [QUOTE]Returning the text, even the original text, will stop this from being called in any other hooks. [b]If you're not changing the text, then you don't return anything.[/b] [/QUOTE] the if statement is just so that it doesn't return an unchanged text.
Oh, my bad. In that case, gsub returns a second argument of the number of characters changed, you can use that as well.
Thank you a lot guys, but where should I put the lua file? lua/autorun/server?
I got access to the server FTP, and I'm supposed to upload it.
Yeah, put it in lua/autorun/server.
[QUOTE=PortalGod;26491110][lua] string.gsub("Herp derp text", "[^%w%p%s]", "") [/lua] That will give you a string that has all non-AlphaNumeric characters removed.[/QUOTE] [code][%W%P%S][/code] Using a capital letter version of a case inverts it.
I know, but using a caret does the same thing, and I think it's less confusing.
Sorry, you need to Log In to post a reply to this thread.