GetPlayerFromAccountName: Difference between revisions
Jump to navigation
Jump to search
m (tweak code) |
|||
| Line 14: | Line 14: | ||
==Code== | ==Code== | ||
<syntaxhighlight lang="lua">function getPlayerFromAccountName(name) | <syntaxhighlight lang="lua"> | ||
local acc = getAccount (name) | function getPlayerFromAccountName(name) | ||
if | local acc = getAccount(name) | ||
if not acc or isGuestAccount(acc) then | |||
return false | return false | ||
end | end | ||
end</syntaxhighlight> | return getAccountPlayer(acc) | ||
end | |||
</syntaxhighlight> | |||
==Example== | ==Example== | ||
Revision as of 00:44, 13 May 2020
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,false if player not found.
Code
function getPlayerFromAccountName(name)
local acc = getAccount(name)
if not acc or isGuestAccount(acc) then
return false
end
return getAccountPlayer(acc)
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.