joaosilva099 Posted September 10, 2014 Posted September 10, 2014 Hi all i have commands in my server that should have an arg that is a player nickname My problem is that i have to type the nickname exactly same the player's nickname. I saw other servers that you just type (example) "t/loc Joao" and the script gets my full name that is (example) "|SS|Joao|F" I searched the wiki already but how can i get the player's nick with approximated name?
joaosilva099 Posted September 10, 2014 Author Posted September 10, 2014 No it is not i want get the player element from a part of his nickname
darhal Posted September 10, 2014 Posted September 10, 2014 i understand u use this function function findPlayer(player) if player and type(player) == "string" then local plr = getPlayerFromName if plr then return plr end local pC = 0 local player = string.lower(player) local spl = split(player, string.byte("[")) if spl then player = table.contact(spl, ";") end for k, v in ipairs(getElementsByType("player") do local nam = string.lower(getPlayerName(v) local spl = split(nam, string.byte("[")) if spl then nam = table.contact(spl, ";") end if string.find(name, player) then plr = v pC = pC + 1 end end if plr and pC == 1 then return plr end return false else return false end end --- copy this function and use it like this -- player = findPlayer(partOfPlayerName)
joaosilva099 Posted September 10, 2014 Author Posted September 10, 2014 I think you helped me!! I cant test now in my mobile but tomorow i test on pc. This will return the player element right? Or the player's complete name?
darhal Posted September 10, 2014 Posted September 10, 2014 It return the player element the code is kinda messy i dont test it (i write it using mobile)
joaosilva099 Posted September 10, 2014 Author Posted September 10, 2014 Edited some things that were error like "no elements in the function getPlayerFromName" and "table concat instead of table contact but still not working function findPlayer(player) if (player and type(player) == "string") then local plr = getPlayerFromName(player) if (plr ~= false) then return plr end local pC = 0 local player = string.lower(player) local spl = split(player, string.byte("[")) if spl then player = table.concat(spl, ";") end for k, v in ipairs(getElementsByType("player")) do local nam = string.lower(getPlayerName(v)) local spl = split(nam, string.byte("[")) if spl then nam = table.concat(spl, ";") end if string.find(name, player) then plr = v pC = pC + 1 end end if plr and pC == 1 then return plr end return false else return false end end
joaosilva099 Posted September 10, 2014 Author Posted September 10, 2014 Found the bug... "name" and "nam". Not tested yet but soon give u feedback
joaosilva099 Posted September 10, 2014 Author Posted September 10, 2014 If u have skype can gime ur name?
darhal Posted September 10, 2014 Posted September 10, 2014 cant using phone i wil add u tommorow using pc
pa3ck Posted September 12, 2014 Posted September 12, 2014 function findPlayer ( pName ) if not pName then return end -- Make sure we have a name to look for local players = {} -- Create a table in case of finding more than 1 player with the matching name for k, element in ipairs ( getElementsByType ( "player") ) do -- start looping the players and check the name against their name local name = getPlayerName ( element ) -- Get their name if string.find ( name, pName ) then -- Check it against the name we are looking for table.insert ( players, element ) -- Save it into our table end end if #players > 1 then -- If found more than 1, return the whole table with the players matching the name return players elseif #players == 1 then -- If we found only one, return that single element return players [ 1 ] else -- we haven`t found anything, return false return false end end
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