Template:Server client function: Difference between revisions
Jump to navigation
Jump to search
m (Reverted edits by Uc.Setlings (talk) to last revision by Qaisjp) |
No edit summary |
||
Line 1: | Line 1: | ||
==Syntax== | |||
<syntaxhighlight lang="lua"> | |||
player getPlayerFromAccountName ( string accountName ) | |||
</syntaxhighlight> | |||
===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== | |||
<syntaxhighlight lang="lua">function getPlayerFromAccountName(name) | |||
if name then | |||
for i,player in ipairs ( getElementsByType ("player") ) do | |||
local acc = getPlayerAccount (player) | |||
if not isGuestAccount (acc) then | |||
if getAccountName (acc) == name then | |||
return player | |||
end | |||
else | |||
return false | |||
end | |||
end | |||
else | |||
return false | |||
end | |||
end</syntaxhighlight> | |||
==Example== | |||
This example get player from account name by command | |||
<syntaxhighlight lang="lua"> | |||
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 | |||
) | |||
</syntaxhighlight> | |||
'''Author: ,#Na[W]aF'1000.''' |
Revision as of 16:33, 16 April 2017
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) if name then for i,player in ipairs ( getElementsByType ("player") ) do local acc = getPlayerAccount (player) if not isGuestAccount (acc) then if getAccountName (acc) == name then return player end else return false end end else return false end end
Example
This example get player 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.