AR/setAccountData: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(Created page with "{{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 co...")
 
m (Добавление языков)
 
(7 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{Server function}}
{{Server function}}
__NOTOC__
__NOTOC__ {{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.}}
{{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. 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.
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.


Line 9: Line 8:
</syntaxhighlight>  
</syntaxhighlight>  


===Required Arguments===  
===العناصر المطلوبة===  
*'''theAccount:''' The account you wish to retrieve the data from.
*'''theAccount:''' إن الحساب الذي تريد استرداد البيانات من.
*'''key:''' The key under which you wish to store the data
*'''key:''' مفتاح تحت التي كنت ترغب في تخزين البيانات
*'''value:''' The value you wish to store. '''NOTE:''' you cannot store tables as values, but you can use [[toJSON]] strings.
*'''value:''' The value you wish to store. '''NOTE:''' you cannot store tables as values, but you can use [[toJSON]] strings.


===Returns===
===Returns===
Returns a ''true'' if the account data was set, ''false'' if an invalid argument was specified.
ترجع صحيح إذا تم تعيين بيانات حسابك، كاذبة إذا تم تحديد وسيطة غير صالحة.


==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.
لقرصان الأدوار gametype، ويرصد مبلغ من المال لاعب الثابتة عن طريق تخزينه في حسابه. ملاحظة يستخدم رمز "piraterpg.money" كمفتاح بدلا من مجرد "المال"، كما يجوز المشاركة للاعب في gametypes الأخرى التي توفر أيضا له مبلغ من المال لله الحساب. If both gametypes would use "money" as the account key, they'd overwrite each other's data.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
function onPlayerQuit ( )
function onPlayerQuit ( )
       -- when a player leaves, store his current money amount in his account data
       -- عندما يترك لاعب، متجره المبلغ من المال الحالية في بيانات حسابه
       local playeraccount = getPlayerAccount ( source )
       local playeraccount = getPlayerAccount ( source )
       if ( playeraccount ) and not isGuestAccount ( playeraccount ) then -- if the player is logged in
       if ( playeraccount ) and not isGuestAccount ( playeraccount ) then -- إذا تم تسجيل اللاعب
             local playermoney = getPlayerMoney ( source ) -- get the player money
             local playermoney = getPlayerMoney ( source ) -- الحصول على المال الاعب
             setAccountData ( playeraccount, "piraterpg.money", playermoney ) -- save it in his account
             setAccountData ( playeraccount, "piraterpg.money", playermoney ) -- حفظها في حسابه
       end
       end
end
end
   
   
function onPlayerLogin (_, playeraccount )
function onPlayerLogin (_, playeraccount )
       -- when a player logins, retrieve his money amount from his account data and set it
       -- عندما تسجيلات لاعب، استرداد له مبلغ من المال من بيانات حسابه وضعه
       if ( playeraccount ) then
       if ( playeraccount ) then
             local playermoney = getAccountData ( playeraccount, "piraterpg.money" )
             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
             if ( playermoney ) then
                   setPlayerMoney ( source, playermoney )
                   setPlayerMoney ( source, playermoney )
Line 45: Line 44:
</syntaxhighlight>
</syntaxhighlight>


==See Also==
==انظر ايضا==
{{AR Account_functions}}
{{AR Account_functions}}


[[en:setAccountData]]
[[en:setAccountData]]
[[ru:setAccountData]]
[[ar:setAccountData]]
[[es:setAccountData]]
[[es:setAccountData]]

Latest revision as of 15:46, 12 April 2021

[[{{{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 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.

Syntax

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

العناصر المطلوبة

  • theAccount: إن الحساب الذي تريد استرداد البيانات من.
  • key: مفتاح تحت التي كنت ترغب في تخزين البيانات
  • value: The value you wish to store. NOTE: you cannot store tables as values, but you can use toJSON strings.

Returns

ترجع صحيح إذا تم تعيين بيانات حسابك، كاذبة إذا تم تحديد وسيطة غير صالحة.

مثال

لقرصان الأدوار gametype، ويرصد مبلغ من المال لاعب الثابتة عن طريق تخزينه في حسابه. ملاحظة يستخدم رمز "piraterpg.money" كمفتاح بدلا من مجرد "المال"، كما يجوز المشاركة للاعب في gametypes الأخرى التي توفر أيضا له مبلغ من المال لله الحساب. 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 ) and not isGuestAccount ( playeraccount ) then -- إذا تم تسجيل اللاعب
            local playermoney = getPlayerMoney ( source ) -- الحصول على المال الاعب
            setAccountData ( playeraccount, "piraterpg.money", playermoney ) -- حفظها في حسابه
      end
end
 
function onPlayerLogin (_, playeraccount )
      -- عندما تسجيلات لاعب، استرداد له مبلغ من المال من بيانات حسابه وضعه
      if ( playeraccount ) then
            local playermoney = getAccountData ( playeraccount, "piraterpg.money" )
            -- تأكد من أن هناك فعلا قيمة المحفوظة تحت هذا المفتاح (معرفة ما اذا كان مال الاعب ليست كاذبة).
            -- وهذا على سبيل المثال سوف لا يكون الأمر كذلك عندما لاعب يلعب قيم تايب لأول مرة
            if ( playermoney ) then
                  setPlayerMoney ( source, playermoney )
            end
      end
end
 
addEventHandler ( "onPlayerQuit", getRootElement ( ), onPlayerQuit )
addEventHandler ( "onPlayerLogin", getRootElement ( ), onPlayerLogin)

انظر ايضا