GetPlayerFromAccountName: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
Line 15: Line 15:
==Code==
==Code==
<syntaxhighlight lang="lua">function getPlayerFromAccountName(name)  
<syntaxhighlight lang="lua">function getPlayerFromAccountName(name)  
     if name then
     local acc = getAccount (name)
        for i,player in ipairs ( getElementsByType ("player") ) do
    if name and acc and not isGuestAccount (acc) then
            local acc = getPlayerAccount (player)
        return getAccountPlayer (acc)
            if not isGuestAccount (acc) then
                if getAccountName (acc) == name then
                    return player
                end
            else
                return false
            end
        end
     else
     else
         return false
         return false

Revision as of 17:36, 16 April 2017


This function get online player from their account name.

Syntax

player getPlayerFromAccountName ( string accountName )

Required Arguments

  • accountName: A string containing account name of a player you want to reference.

Returns

Returns a player if the account name exists,nil if player not found.

Code

function getPlayerFromAccountName(name) 
    local acc = getAccount (name)
    if name and acc and not isGuestAccount (acc) then
        return getAccountPlayer (acc)
    else
        return false
    end
end

Example

This example get player name from account name by command

addCommandHandler ("getPlayerName",
    function (player,_,name)
        if name then
        local thePlayer = getPlayerFromAccountName (name)
        if thePlayer then
            outputChatBox (getPlayerName (thePlayer),player,255,255,255,true)
        else
            outputChatBox ("player not found !",player,255,0,0)
        end
    else
        outputChatBox ("type account name frist !",player,255,255,0)
    end
end
)

Author: ,#Na[W]aF'1000.