Jump to content

getPlayer(thePlayer)


#Paper

Recommended Posts

The table.string in bad argument :S

function getPlayer(thePlayer) 
local players = {} 
for id, player in ipairs(getElementsByType("player")) do 
    local playerName = getPlayerName(player) 
    local playerName = playerName:gsub("#%x%x%x%x%x%x", "") 
    table.insert(players, playerName) 
end 
if string.find(players, thePlayer) then 
return playerName 
else 
return false 
end 
end 

Link to comment
function getPlayer(thePlayer) 
local players = {} 
for id, player in ipairs(getElementsByType("player")) do 
    local playerName = getPlayerName(player) 
    local playerName = playerName:gsub("#%x%x%x%x%x%x", "") 
    table.insert(players, playerName) 
end 
if string.find(players, thePlayer) then 
return playerName 
else 
return false 
end 
end 

Why do you need a table for this?

also, why do you need to make a new function if there is getPlayerFromName already...?

function getPlayer(thePlayer) 
for id, player in ipairs(getElementsByType("player")) do 
local playerName = getPlayerName(player) 
local playerName2 = playerName:gsub("#%x%x%x%x%x%x", "") 
if string.find(tostring(playerName2), tostring(thePlayer)) then 
return playerName 
else 
return false 
end 
end 

Try it (not tested)

Link to comment
  • Moderators

@SolidSnake: I think that he want to return the playerName whithout the hexa color so it's:

return playerName2 

But I'm sure that you just forgot it ^^

@AcitanoX: You can't make that:

local playerName = something 
local playerName = somethingElse  

But you can like this:

local playerName = something 
playerName = somethingElse 

( I delete the second "local" => but the variable stay to a local variable )

Link to comment
@SolidSnake: I think that he want to return the playerName whithout the hexa color so it's:
return playerName2 

But I'm sure that you just forgot it ^^

@AcitanoX: You can't make that:

local playerName = something 
local playerName = somethingElse  

But you can like this:

local playerName = something 
playerName = somethingElse 

( I delete the second "local" => but the variable stay to a local variable )

the same thing, doesn't work...

Link to comment
  • Moderators

Ok I understood your function and I modify it like if I have to make this function myself ( almost the same ):

Your function fixed:

function getPlayer(thePlayerName) 
    for id, player in ipairs(getElementsByType("player")) do 
        local playerName = getPlayerName(player) 
        --local playerName2 = playerName:gsub("#%x%x%x%x%x%x", "") -- not needed 
        if ( string.find( tostring( thePlayerName ), tostring( playerName ) ) then 
            return playerName 
        else 
            return false 
        end 
    end 
end 

My function ( optimized ):

function getPlayer(thePlayerName) 
    for id, player in ipairs(getElementsByType("player")) do 
        if ( string.find( tostring( thePlayerName ), tostring( getPlayerName(player) ) ) then 
            return getPlayerName(player) 
        else 
            return false 
        end 
    end 
end 

Link to comment
Ok I understood your function and I modify it like if I have to make this function myself ( almost the same ):

Your function fixed:

function getPlayer(thePlayerName) 
    for id, player in ipairs(getElementsByType("player")) do 
        local playerName = getPlayerName(player) 
        --local playerName2 = playerName:gsub("#%x%x%x%x%x%x", "") -- not needed 
        if ( string.find( tostring( thePlayerName ), tostring( playerName ) ) then 
            return playerName 
        else 
            return false 
        end 
    end 
end 

Why don't needed? I i type "AcitanoX" and my nick is "#ff00ffAcit#00ff00anoX" the server can't get AcitanoX player, because the nick is separed by the codes...

Link to comment
  • Moderators

yeah sorry, I just see that in my mind:

"#ff00ffAcitanoX" so it can find Acitanox whithout the gsub ^^

The new code:

function getPlayer(thePlayerName) 
    for id, player in ipairs(getElementsByType("player")) do 
        local playerName = getPlayerName(player) 
        local playerName2 = playerName:gsub("#%x%x%x%x%x%x", "") 
        if ( string.find( tostring( thePlayerName ), tostring( playerName2 ) ) then 
            return playerName 
        else 
            return false 
        end 
    end 
end 

It's almost the same as the SolidSnake code, I just added a missed end :P

Link to comment
yeah sorry, I just see that in my mind:

"#ff00ffAcitanoX" so it can find Acitanox whithout the gsub ^^

The new code:

function getPlayer(thePlayerName) 
    for id, player in ipairs(getElementsByType("player")) do 
        local playerName = getPlayerName(player) 
        local playerName2 = playerName:gsub("#%x%x%x%x%x%x", "") 
        if ( string.find( tostring( thePlayerName ), tostring( playerName2 ) ) then 
            return playerName 
        else 
            return false 
        end 
    end 
end 

It's almost the same as the SolidSnake code, I just added a missed end :P

it's "#ff00ffAcit#00ff00anoX" and if i type "AcitanoX" i must retrieve "#ff00ffAcit#00ff00anoX" player...

Link to comment
  
function getPlayer(thePlayerName) 
    for id, player in ipairs(getElementsByType("player")) do 
        local playerName   = getPlayerName(player):gsub("#%x%x%x%x%x%x", "") 
  
        if ( string.find ( tostring( thePlayerName ), tostring( playerName ) ) then 
            return playerName 
        end 
    end 
  
    return false 
end 
  

Link to comment
  
function getPlayer(thePlayerName) 
    for id, player in ipairs(getElementsByType("player")) do 
        local playerName   = getPlayerName(player):gsub("#%x%x%x%x%x%x", "") 
  
        if ( string.find ( tostring( thePlayerName ), tostring( playerName ) ) then 
            return playerName 
        end 
    end 
  
    return false 
end 
  

LoL, it works, ty :D

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