Jump to content

getPlayer(thePlayer)


#Paper

Recommended Posts

Posted

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 

mtaubluascripter.png

My skype: skiper964

I helped you? Help me! ^^

Help me bro! ^^

Posted
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)

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.

  • Moderators
Posted

@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 rEvolution is coming ...

Posted

You are right Citizen, i forgot about that :P

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

mtaubluascripter.png

My skype: skiper964

I helped you? Help me! ^^

Help me bro! ^^

  • Moderators
Posted

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 

The rEvolution is coming ...

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

mtaubluascripter.png

My skype: skiper964

I helped you? Help me! ^^

Help me bro! ^^

  • Moderators
Posted

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

The rEvolution is coming ...

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

mtaubluascripter.png

My skype: skiper964

I helped you? Help me! ^^

Help me bro! ^^

Posted
  
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 
  

Posted
  
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

mtaubluascripter.png

My skype: skiper964

I helped you? Help me! ^^

Help me bro! ^^

  • Moderators
Posted

Hahahaha, I forgot again this:

return playerName2 

instead of

return playerName 

:|

The rEvolution is coming ...

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