GetPlayerAccount: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
mNo edit summary
m (Добавление языков)
 
(13 intermediate revisions by 9 users not shown)
Line 1: Line 1:
{{Needs Checking|Should this page be removed, as the function doesn't seem to be implented at all? There's already [[getClientAccount]]. --[[User:Awwu|Awwu]] 08:57, 5 April 2008 (CDT)}}
__NOTOC__
__NOTOC__  
{{Server function}}
{{Server function}}
Returns the accountname of the player
This function returns the specified player's [[account]] object.


==Syntax==  
==Syntax==
<syntaxhighlight lang="lua">string getPlayerAccount ( player thePlayer )</syntaxhighlight>  
<syntaxhighlight lang="lua">
 
account getPlayerAccount ( player thePlayer )
===Required Arguments===  
</syntaxhighlight>
*'''thePlayer:''' The player you wish the retrieve the name of the account from.
{{OOP|Static method [[Account]].getFromPlayer() can also be used|[[player]]:getAccount|account|}}
===Required Arguments===
* '''thePlayer:''' The [[player]] element you want to get the [[account]] of.


===Returns===
===Returns===
Returns an string with name of the account.
Returns the player's account object, or ''false'' if the player passed to the function is invalid.
-- TODO -- What does it return if it isnt known?


==Example==
==Example==
When a player types '/account' this example retrieves the player's accountname, and prints it to his screen.
This example sets a player's money and also stores the value is his account.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
function viewAccount(thePlayer, command)
function setMoney(thePlayer,key,amount)
-- get the name of the account from thePlayer
    local account = getPlayerAccount(thePlayer)
local accountName = getPlayerAccount(thePlayer)  
    if account and tonumber(amount) then
        setPlayerMoney (thePlayer,amount)
-- output the message to the player
        setAccountData(account,"money",amount)
outputChatBox("Your account name is " .. accountName, thePlayer)
    end
end
end
 
addCommandHandler("setmoney",setMoney)
-- add the console command
addCommandHandler("account", viewAccount)                                  
</syntaxhighlight>
</syntaxhighlight>


==See Also==
==See Also==
{{Player functions}}
{{Account_functions}}
[[Category:Incomplete]]
 
[[en:getPlayerAccount]]
[[ru:getPlayerAccount]]
[[hu:getPlayerAccount]]
[[ar:getPlayerAccount]]
[[zh-cn:getPlayerAccount]]

Latest revision as of 13:42, 12 April 2021

This function returns the specified player's account object.

Syntax

account getPlayerAccount ( player thePlayer )

OOP Syntax Help! I don't understand this!

Note: Static method Account.getFromPlayer() can also be used
Method: player:getAccount(...)
Variable: .account


Required Arguments

Returns

Returns the player's account object, or false if the player passed to the function is invalid.

Example

This example sets a player's money and also stores the value is his account.

function setMoney(thePlayer,key,amount)
    local account = getPlayerAccount(thePlayer)
    if account and tonumber(amount) then
        setPlayerMoney (thePlayer,amount)
        setAccountData(account,"money",amount)
    end
end
addCommandHandler("setmoney",setMoney)

See Also