AR/getAccountData: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
mNo edit summary
m (Добавление языков)
 
(5 intermediate revisions by 2 users not shown)
Line 2: Line 2:
{{Server function}}
{{Server function}}
__NOTOC__
__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.}}
{{Important Note|You '''MUST''' use the standard ''module.key'' naming for your keys, as shown in the example below. This prevents collisions between different scripts.}}
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.
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.


Line 11: Line 11:


===Required Arguments===  
===Required Arguments===  
*'''theAccount:''' The account you wish to retrieve the data from.
*'''theAccount:''' الحساب الذي يرغب في استرداد البيانات منه.
*'''key:''' The key under which the data is stored
*'''key:''' المفتاح الذي بموجبه يتم تخزين البيانات


===Returns===
===Returns===
Returns a [[string]] containing the stored data or ''false'' if no data was stored under that key.
 
.بإرجاع [[سلسلة]] تحتوي على البيانات المخزنة أو ''خاطئة'' إذا تم تخزين أية بيانات تحت هذا المفتاح


==Example==
==Example==
Line 21: Line 22:
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
function onPlayerQuit()
function onPlayerQuit()
       local playerAccount = getPlayerAccount(source) -- get his account
       local playerAccount = getPlayerAccount(source) -- الحصول على حسابه
       if (playerAccount) then -- if we got the account then
       if (playerAccount) then -- if we got the account then
             local playerMoney = getPlayerMoney(source) -- get his money amount
             local playerMoney = getPlayerMoney(source) -- يحصل على مبلغ من المال
             setAccountData(playerAccount, "piraterpg.money", playerMoney) -- store his current money amount in his account data
             setAccountData(playerAccount, "piraterpg.money", playerMoney) -- تخزين له مبلغ من المال الحالي في بيانات حسابه
       end
       end
end
end
addEventHandler("onPlayerQuit", getRootElement(), onPlayerQuit) -- add an event handler
addEventHandler("onPlayerQuit", getRootElement(), onPlayerQuit) -- إضافة معالج أحداث


function onPlayerLogin()
function onPlayerLogin()
Line 33: Line 34:
       local playerAccount = getPlayerAccount(source) -- get his account
       local playerAccount = getPlayerAccount(source) -- get his account
       if (playerAccount) then -- if we got the account then
       if (playerAccount) then -- if we got the account then
             local playerMoney = getAccountData(playerAccount, "piraterpg.money") -- get the money amount was store in his account data
             local playerMoney = getAccountData(playerAccount, "piraterpg.money") -- الحصول تم تخزين كمية من المال في حسابه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
             if (playerMoney) then
                   setPlayerMoney(source, playerMoney)
                   setPlayerMoney(source, playerMoney)
Line 49: Line 50:
[[en:getAccountData]]
[[en:getAccountData]]
[[ru:getAccountData]]
[[ru:getAccountData]]
[[ar:getAccountData]]
[[pl:getAccountData]]
[[zh-cn:getAccountData]]

Latest revision as of 20:04, 11 April 2021

Warning.png This page requires local translation. If page will remain not translated in reasonable period of time it would be deleted.
After translating the page completely, please remove the ‎{{translate}}‎ tag from the page.


[[{{{image}}}|link=|]] Important Note: You MUST use the standard module.key naming for your keys, as shown in the example below. This prevents collisions between different scripts.

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.

Syntax

string getAccountData ( account theAccount, string key )

Required Arguments

  • theAccount: الحساب الذي يرغب في استرداد البيانات منه.
  • key: المفتاح الذي بموجبه يتم تخزين البيانات

Returns

.بإرجاع سلسلة تحتوي على البيانات المخزنة أو خاطئة إذا تم تخزين أية بيانات تحت هذا المفتاح

Example

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()
      local playerAccount = getPlayerAccount(source) -- الحصول على حسابه
      if (playerAccount) then -- if we got the account then
            local playerMoney = getPlayerMoney(source) -- يحصل على مبلغ من المال
            setAccountData(playerAccount, "piraterpg.money", playerMoney) -- تخزين له مبلغ من المال الحالي في بيانات حسابه
      end
end
addEventHandler("onPlayerQuit", getRootElement(), onPlayerQuit) -- إضافة معالج أحداث

function onPlayerLogin()
      -- when a player logins, retrieve his money amount from his account data and set it
      local playerAccount = getPlayerAccount(source) -- get his account
      if (playerAccount) then -- if we got the account then
            local playerMoney = getAccountData(playerAccount, "piraterpg.money") -- الحصول تم تخزين كمية من المال في حسابهdata
            -- تأكد من وجود في الواقع قيمة المحفوظة تحت هذا المفتاح (معرفة ما اذا كان لاعب المال ليس كاذبة)ا.
            -- هذه الإرادة على سبيل المثال لا يكون الأمر كذلك عندما لاعب يلعب نوع اللعبة للمرة الأولى.
            if (playerMoney) then
                  setPlayerMoney(source, playerMoney)
            end
      end
end
addEventHandler("onPlayerLogin", getRootElement(), onPlayerLogin) -- add an event handler

See Also