GetPlayerAccount: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
m (fix oop syntax)
mNo edit summary
Line 18: Line 18:
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
function setMoney(thePlayer,key,amount)
function setMoney(thePlayer,key,amount)
    setPlayerMoney (thePlayer,amount)
     local account = getPlayerAccount(thePlayer)
     local account = getPlayerAccount(thePlayer)
     if account and tonumber(amount) then
     if account and tonumber(amount) then
        setPlayerMoney (thePlayer,amount)
         setAccountData(account,"money",amount)
         setAccountData(account,"money",amount)
     end
     end

Revision as of 13:25, 31 July 2016

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