Jump to content

[HELP] Commands


joaosilva099

Recommended Posts

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?

Link to comment

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) 
   
  

Link to comment

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 
  

Link to comment
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 

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