ES/getAccountData

From Multi Theft Auto: Wiki
Revision as of 08:38, 7 September 2019 by Qaisjp (talk | contribs) (prefer normal note)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

[[{{{image}}}|link=|]] Note: Es muy importante que nombres tus claves de la forma modulo.clave, como se muestra en el ejemplo. Esto previene interferencias con otros scripts.

Esta función obtiene la información que fue guardada en una cuenta usando setAccountData. La información guardada en una cuenta no se borra cuando el jugador deja el servidor o cambia de mapa.

Sintaxis

string getAccountData ( account laCuenta, string laClave)

Argumentos Requeridos

  • laCuenta: La cuenta de la cual quieres obtener información.
  • laClave: La clave bajo la cual esta guardada la información.

Devuelve

Devuelve una string(cadena de texto) con la información requerida o false si no hay información guardada bajo esa clave.

Ejemplos

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.

function onPlayerQuit ( )
      -- when a player leaves, store his current money amount in his account data
      local playeraccount = getPlayerAccount ( source )
      if ( playeraccount ) then
            local playermoney = getPlayerMoney ( source )
            setAccountData ( playeraccount, "piraterpg.money", playermoney )
      end
end

function onPlayerJoin ( )
      -- when a player joins, retrieve his money amount from his account data and set it
      local playeraccount = getPlayerAccount ( source )
      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 ( "onPlayerJoin", getRootElement ( ), onPlayerJoin )

See Also

BEFORE VERSION 1.0 :