diegofkda Posted June 17, 2011 Share Posted June 17, 2011 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
diegofkda Posted June 17, 2011 Author Share Posted June 17, 2011 How to use? don't know much in that part . Link to comment
JR10 Posted June 17, 2011 Share Posted June 17, 2011 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
diegofkda Posted June 17, 2011 Author Share Posted June 17, 2011 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
JR10 Posted June 17, 2011 Share Posted June 17, 2011 Yea but this way the player might have (Fp) or [fp] or |fP| so it's better to lower both strings. Link to comment
diegofkda Posted June 17, 2011 Author Share Posted June 17, 2011 And how to delete a part of the nick? Link to comment
JR10 Posted June 17, 2011 Share Posted June 17, 2011 local playerName = getPlayerName(player) newPlayerName = playerName:gsub('[FP]', '') setPlayerName(player, newPlayerName) Link to comment
Aibo Posted June 18, 2011 Share Posted June 18, 2011 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
JR10 Posted June 18, 2011 Share Posted June 18, 2011 I can't understand any thing of this: newn:find("[%[%(%|][fF][pP][%]%)%|]*") newPlayerName = playerName:gsub("[%[%(%|][fF][pP][%]%)%|]*", "") i just don't understand those patterns. Link to comment
Aibo Posted June 18, 2011 Share Posted June 18, 2011 well, time to learn then :3 http://lua-users.org/wiki/PatternsTutorial it's a good thing © Link to comment
JR10 Posted June 18, 2011 Share Posted June 18, 2011 (edited) So i can use this if string.find('mtaft', '[mta]', 0) will it find mta ? Edited June 18, 2011 by Guest Link to comment
Aibo Posted June 18, 2011 Share Posted June 18, 2011 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
JR10 Posted June 18, 2011 Share Posted June 18, 2011 1 question why you use % before each [ or | or ( else i understand. thanks btw i learned something new Link to comment
Aibo Posted June 18, 2011 Share Posted June 18, 2011 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
JR10 Posted June 18, 2011 Share Posted June 18, 2011 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
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