developa Posted September 6, 2017 Share Posted September 6, 2017 Hi, can I turn this into a more optimal way? addEventHandler("onPlayerConnect", root, function(nick) if string.find(nick, "#") or string.find(nick, "?") or string.find(nick, "!") then cancelEvent(true, "Change nickname!") end end) For example nick:find("#")? Link to comment
Administrators Lpsd Posted September 6, 2017 Administrators Share Posted September 6, 2017 (edited) local invalid_chars = {"#", "?", "!"} addEventHandler("onPlayerConnect", root, function(nick) for i=1,#invalid_chars do local escape if not string.match(invalid_chars[i], "[^a-zA-Z0-9]") then escape = "%" else escape = "" end if nick:find(escape..invalid_chars[i]) then cancelEvent(true, "Change nickname!") return end end end) I don't know about optimal, but it's definitely easier to manage. updated code to allow for escaping special characters on :find Edited September 6, 2017 by LopSided_ Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now