SetAccountData: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
mNo edit summary
No edit summary
Line 1: Line 1:
__NOTOC__  
{{Server function}}
__NOTOC__
{{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.}}
{{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.}}
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.
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.
Line 17: Line 18:


==Example==  
==Example==  
Need onPlayerLogin for this...
On a roleplaying server, save the money of a player when he quits, so it can be loaded again when he comes back later.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
function onPlayerQuit ( )
      local playeraccount = getClientAccount ( source )
      local playermoney = getPlayerMoney ( source )
      setAccountData ( playeraccount, "piraterpg.money", playermoney )
end


function onPlayerJoin ( )
      local playeraccount = getClientAccount ( source )
      local playermoney = getAccountData ( playeraccount, "piraterpg.money" )
      setPlayerMoney ( source, playermoney )
end
addEventHandler ( "onPlayerQuit", getRootElement ( ), onPlayerQuit )
addEventHandler ( "onPlayerJoin", getRootElement ( ), onPlayerJoin )
</syntaxhighlight>
</syntaxhighlight>



Revision as of 15:15, 16 August 2007

This template is no longer in use as it results in poor readability. 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.

Syntax

bool setAccountData ( account theAccount, string key, string value )

Required Arguments

  • theAccount: The account you wish to retrieve the data from.
  • key: The key under which you wish to store the data
  • value: The value you wish to store

Returns

Returns a true if the account data was set, false if an invalid argument was specified.

Example

On a roleplaying server, save the money of a player when he quits, so it can be loaded again when he comes back later.

function onPlayerQuit ( )
      local playeraccount = getClientAccount ( source )
      local playermoney = getPlayerMoney ( source )
      setAccountData ( playeraccount, "piraterpg.money", playermoney )
end

function onPlayerJoin ( )
      local playeraccount = getClientAccount ( source )
      local playermoney = getAccountData ( playeraccount, "piraterpg.money" )
      setPlayerMoney ( source, playermoney )
end

addEventHandler ( "onPlayerQuit", getRootElement ( ), onPlayerQuit )
addEventHandler ( "onPlayerJoin", getRootElement ( ), onPlayerJoin )

See Also