ZH-CN/getAccountData: Difference between revisions
Jump to navigation
Jump to search
Qwe7769611 (talk | contribs) No edit summary |
m (Добавление языков) |
||
(4 intermediate revisions by one other user not shown) | |||
Line 1: | Line 1: | ||
{{Server function}} | {{Server function}} | ||
__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.}} | __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.}} | ||
此函数用于检索使用[[setAccountData]]存储的字符串. Data stored as account data is persistent across user's sessions and maps, unless they are logged into a guest account. | |||
== | ==语法== | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
string getAccountData ( account theAccount, string key ) | string getAccountData ( account theAccount, string key ) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
{{ | {{OOP_ZH-CN||[[account]]:getData||setAccountData}} | ||
=== | ===必填参数=== | ||
*'''theAccount:''' | *'''theAccount:''' 要从中检索数据的帐户. | ||
*'''key:''' | *'''key:''' 存储数据的密钥(key) | ||
=== | ===返回值=== | ||
返回包含存储数据的[[string]],如果该键下未存储数据,则返回“false”。 | |||
== | ==示例== | ||
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. | 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. | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
function onPlayerQuit() | function onPlayerQuit() | ||
local playerAccount = getPlayerAccount(source) -- | local playerAccount = getPlayerAccount(source) -- 获取他的账户 | ||
if (playerAccount) then -- | if (playerAccount) then -- 如果确认账户存在 | ||
local playerMoney = getPlayerMoney(source) -- | local playerMoney = getPlayerMoney(source) -- 获取他的金钱 | ||
setAccountData(playerAccount, "piraterpg.money", playerMoney) -- | setAccountData(playerAccount, "piraterpg.money", playerMoney) -- 把他现在的钱存到他的账户里 | ||
end | end | ||
end | end | ||
addEventHandler("onPlayerQuit", root, onPlayerQuit) -- | addEventHandler("onPlayerQuit", root, onPlayerQuit) -- 添加事件处理程序 | ||
function onPlayerLogin(_,account) | function onPlayerLogin(_,account) | ||
Line 35: | Line 35: | ||
end | end | ||
end | end | ||
addEventHandler("onPlayerLogin", root, onPlayerLogin) -- | addEventHandler("onPlayerLogin", root, onPlayerLogin) -- 添加事件处理程序 | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Line 41: | Line 41: | ||
{{Account_functions}} | {{Account_functions}} | ||
[[en:getAccountData]] | |||
[[ru:getAccountData]] | [[ru:getAccountData]] | ||
[[ar:getAccountData]] | [[ar:getAccountData]] | ||
[[pl:getAccountData]] | [[pl:getAccountData]] | ||
[[zh-cn:getAccountData]] | [[zh-cn:getAccountData]] |
Latest revision as of 20:05, 11 April 2021
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. |
此函数用于检索使用setAccountData存储的字符串. Data stored as account data is persistent across user's sessions and maps, unless they are logged into a guest account.
语法
string getAccountData ( account theAccount, string key )
OOP 语法 什么是OOP?
- 方法: account:getData(...)
- 对称函数: setAccountData
必填参数
- theAccount: 要从中检索数据的帐户.
- key: 存储数据的密钥(key)
返回值
返回包含存储数据的string,如果该键下未存储数据,则返回“false”。
示例
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 -- 如果确认账户存在 local playerMoney = getPlayerMoney(source) -- 获取他的金钱 setAccountData(playerAccount, "piraterpg.money", playerMoney) -- 把他现在的钱存到他的账户里 end end addEventHandler("onPlayerQuit", root, onPlayerQuit) -- 添加事件处理程序 function onPlayerLogin(_,account) local playerMoney = getAccountData(account, "piraterpg.money") -- get the money amount was store in his account 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 setPlayerMoney(source, playerMoney) end end addEventHandler("onPlayerLogin", root, onPlayerLogin) -- 添加事件处理程序
See Also
- addAccount
- copyAccountData
- getAccount
- getAccountData
- getAccountName
- getAccountPlayer
- getAccountSerial
- getAccounts
- getAccountsBySerial
- getAllAccountData
- getPlayerAccount
- isGuestAccount
- logIn
- logOut
- removeAccount
- setAccountData
- setAccountPassword
- getAccountByID
- getAccountID
- getAccountIP
- getAccountsByData
- getAccountsByIP
- setAccountName