Jump to content

Partial nick


Klesh

Recommended Posts

Posted

I was try to make some function to later insert it for a command script:

    function getPlayerFromPartOfName(nickpart) 
      local players=getElementsByType("player") 
      local matches={} 
      for _,v in pairs(players) do 
        if string.find(string.lower(getPlayerFromName(v)),string.lower(nickpart)) then 
          table.insert(matches,v) 
        end 
     end 
     if #mathces>1 then 
       return false 
     else 
       return mathces[1] 
     end 
    end 

Posted

And what doesn't work from it?

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

Maybe because you used getPlayerFromName instead of getPlayerName in line: 5.

Also you put "mathces" instead of "matches".

function getPlayerFromPartOfName(nickpart) 
      local players=getElementsByType("player") 
      local matches={} 
      for _,v in pairs(players) do 
        if string.find(string.lower(getPlayerName(v)),string.lower(nickpart)) then 
          table.insert(matches,v) 
        end 
     end 
     if #matches>1 then 
       return false 
     else 
       return matches[1] 
     end 
    end 

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

Not works.

    function getPlayerFromPartOfName(nickpart) 
          local players=getElementsByType("player") 
          local matches={} 
          for _,v in pairs(players) do 
            if string.find(string.lower(getPlayerName(v)),string.lower(nickpart)) then 
              table.insert(matches,v) 
            end 
         end 
         if #matches>1 then 
           return false 
         else 
           return matches[1] 
         end 
        end 
      

Posted
function getPlayerFromPartOfName(nickpart) 
    local players=getElementsByType("player") 
    local matches={} 
    for _,v in pairs(players) do 
        if string.find(string.lower(getPlayerName(v)),string.lower(nickpart)) then 
            table.insert(matches,v) 
        end 
    end 
    if (#matches > 1) then 
        return false 
    else 
        return matches[1] 
    end 
end 
  
addCommandHandler("part", 
function (thePlayer, cmd, who) 
    local player = getPlayerFromPartOfName(who) 
    if (player) then 
        outputChatBox(getPlayerName(player)) 
    end 
end) 

Works perfectly.

I do /part cast and it outputs (SAUR)Castillo.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

Why delete the topic? if you post here you should know that it's going to be public. It could help someone else with a similar problem.

Not going to be deleted.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

You can report the resource, yes.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

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