Jump to content

string.find


developa

Recommended Posts

  • Administrators
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 by LopSided_
Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...