Jump to content

Something simple


Recommended Posts

Well, I want to know how to get a part of the name, this is my script:

function detectFake(oldn, newn) 
    fakename = findFakeTag(newn) 
    if fakename == "|FP|" or fakename == "[FP]" or fakename == "(FP)" then 
        outputChatBox ("That nametag is not allowed, choose another.", source, 255, 0, 0) 
        cancelEvent() 
    end 
end 
addEventHandler ("onPlayerChangeNick", root, detectFake )  

Link to comment
function detectFake(oldn, newn) 
    if string.find(string.lower(newn), string.lower("|FP|"), 0) or string.find(string.lower(newn), string.lower("[FP]", 0) or string.find(string.lower(newn), string.lower("(FP)"), 0) then 
        outputChatBox ("That nametag is not allowed, choose another.", source, 255, 0, 0) 
        cancelEvent() 
    end 
end 
addEventHandler ("onPlayerChangeNick", root, detectFake ) 

Link to comment
function detectFake(oldn, newn) 
    if string.find(string.lower(newn), string.lower("|FP|"), 0) or string.find(string.lower(newn), string.lower("[FP]", 0) or string.find(string.lower(newn), string.lower("(FP)"), 0) then 
        outputChatBox ("That nametag is not allowed, choose another.", source, 255, 0, 0) 
        cancelEvent() 
    end 
end 
addEventHandler ("onPlayerChangeNick", root, detectFake ) 

Thank you very much! :)

Anyway, should be more easy

function detectFake(oldn, newn) 
    fakename = string.find(newn, "|FP|") 
    fakename2 = string.find(newn, "(FP)") 
    fakename3 = string.find(newn, "[FP]") 
    if fakename or fakename2 or fakename3 then 
            outputChatBox ("That nametag is not allowed, choose another.", source, 255, 0, 0) 
        cancelEvent() 
    end 
end 
addEventHandler ("onPlayerChangeNick", root, detectFake ) 

Link to comment

instead of using string.find 3 times (and string.lower 6 times), you can use patterns.

function detectFake(oldn, newn) 
  -- this will match [fp], (fP), [fP|, or any other combination, regardless the case 
  if newn:find("[%[%(%|][fF][pP][%]%)%|]*") then 
    outputChatBox ("That nametag is not allowed, choose another.", source, 255, 0, 0) 
    cancelEvent() 
  end 
end 
addEventHandler ("onPlayerChangeNick", root, detectFake) 
  
-- you can also use this pattern in gsub: 
newPlayerName = playerName:gsub("[%[%(%|][fF][pP][%]%)%|]*", "") 

EDIT: changed escaping from \ to %, dunno which way is more "correct", but % dont break the string in highligther :3

Link to comment

it will (though in lua string starts at character 1, not 0).

also

string.find('ftwmta', '[mtaftw]', 0) -- true 
string.find('ffffffff', '[mtaftw]', 0) -- true 
-- [mtaftw] is a set of symbols to search for, without any order 
  

Link to comment

because those are magic characters (like in a pattern [ and ] denote a set) and therefore must be escaped if you want to search for them in a string.

not "|" though, as i recall, but i escaped it just in case.

by the way, your string.gsub(playerName, '[FP]', '') will leave [ and ] in the name for the reason above, [FP] is a pattern here.

same applies to the previous string.find. it will just find/replace any F or P letters in the name.

either use plain search option, or escape [ and ].

testName = '[FP]FatPony' 
newName = string.gsub(testName, '[FP]', '') 
-- and the name now is: []atony 

Link to comment

I use ' ' so When i wanted to use a word like "can't" i had to escape it like this 'can\'t' so that's it? that's the escape? and in your example above

testName = '[FP]FatPony' 
newName = string.gsub(testName, '\[FP\]', '') 
-- and the name now is: atony 

Am i right?

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...