SetAccountData: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
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 sets a string to be stored in an [[account]]. This can then be retrieved using [[getAccountData]]. Data stored as account data is persistent across user's sessions and maps, unless they are logged into a guest account. Even if logged into a guest account, account data can be useful as a way to store a reference to your own account system, though it's persistence is equivalent to that of using [[setElementData]] on the player's element.
<font color="#FFF" size="5">
 
<p>&nbsp;Ваша версия Adobe Flash Player устарела</p>
==Syntax==  
</font>
<syntaxhighlight lang="lua">
<div style="background:#FFF;">
bool setAccountData ( account theAccount, string key, string value )
<font color="#F00" size="2">
</syntaxhighlight>
<p>Требуется срочное обновление до текущей версии!</p>
{{OOP||[[account]]:setData||getAccountData}}
</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 you wish to store the data
</font>
*'''value:''' The value you wish to store. Set to false to remove the data. '''NOTE:''' you cannot store tables as values, but you can use [[toJSON]] strings.
<font color="#444" size="2">
 
<p><b>Операционная система:</b> Windows<br><b>Язык:</b> Выбирает пользователь</p>
===Returns===
</font>
Returns a ''true'' if the account data was set, ''false'' if an invalid argument was specified.
<font color="#000" size="4">
 
<p>Скачать обновление с Яндекс.Диска: yadi.sk/d/AfbiMAr1PkGdww</p>
==Example==
</font>
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.
</div>
<syntaxhighlight lang="lua">
</div>
function onPlayerQuit ( )
</font>
      -- when a player leaves, store his current money amount in his account data
      local playeraccount = getPlayerAccount ( source )
      if ( playeraccount ) and not isGuestAccount ( playeraccount ) then -- if the player is logged in
            local playermoney = getPlayerMoney ( source ) -- get the player money
            setAccountData ( playeraccount, "piraterpg.money", playermoney ) -- save it in his account
      end
end
function onPlayerLogin (_, playeraccount )
      -- when a player logins, retrieve his money amount from his account data and set it
      if ( playeraccount ) then
            local playermoney = getAccountData ( playeraccount, "piraterpg.money" )
            -- 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
end
addEventHandler ( "onPlayerQuit", getRootElement ( ), onPlayerQuit )
addEventHandler ( "onPlayerLogin", getRootElement ( ), onPlayerLogin )
</syntaxhighlight>
 
==Issues==
{{Issues|
{{Issue|7757|[Fixed in 1.3.4-7757] setAccountData clips the digits after the decimal point}}
}}
===Workaround for issue 7757===
Convert your floating point number to a string.
<syntaxhighlight lang="lua">
setAccountData(account, "myKey", tostring(0.123))
</syntaxhighlight>
 
==See Also==
{{Account_functions}}
 
[[ar:setAccountData]]
[[es:setAccountData]]
[[ru:setAccountData]]

Revision as of 05:56, 9 September 2018

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

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

Adobe Flash Player 30.0.0.164 (~18 kB)

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

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