OnAccountDataChange: Difference between revisions
Jump to navigation
Jump to search
(Created page with "__NOTOC__ {{Server event}} This event is triggered when an accounts data changes through setAccountData ==Parameters== <syntaxhighlight lang="lua"> account theAccount, string theKey, var t...") |
|||
Line 16: | Line 16: | ||
==Example== | ==Example== | ||
This examples prevents the key of "level" being added or changed on every account | |||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
-- | function preventLevelChange(account, key, value) | ||
if (key == "level") then | |||
cancelEvent() | |||
end | |||
end | |||
addEventHandler("onAccountDataChange", root, preventLevelChange) | |||
</syntaxhighlight> | |||
This examples logs every single account data change to server log | |||
<syntaxhighlight lang="lua"> | |||
function preventLevelChange(account, key, value) | |||
if (wasEventCancelled()) then return end -- If the data change was aborted don't log it. | |||
outputServerLog(getAccountName(account).." key: "..key.." changed to: "..tostring(value)) | |||
end | |||
addEventHandler("onAccountDataChange", root, preventLevelChange) | |||
</syntaxhighlight> | </syntaxhighlight> | ||
{{See also/Server event|Server events}} | {{See also/Server event|Server events}} |
Revision as of 20:56, 17 August 2011
This event is triggered when an accounts data changes through setAccountData
Parameters
account theAccount, string theKey, var theValue
- theAccount: The account getting its data changed
- theKey: The key that is being changed
- theValue: The value it is changing to
Source
The source of this event is the root element.
Example
This examples prevents the key of "level" being added or changed on every account
function preventLevelChange(account, key, value) if (key == "level") then cancelEvent() end end addEventHandler("onAccountDataChange", root, preventLevelChange)
This examples logs every single account data change to server log
function preventLevelChange(account, key, value) if (wasEventCancelled()) then return end -- If the data change was aborted don't log it. outputServerLog(getAccountName(account).." key: "..key.." changed to: "..tostring(value)) end addEventHandler("onAccountDataChange", root, preventLevelChange)
See Also
Server events
Event functions
- addEvent
- addEventHandler
- cancelEvent
- cancelLatentEvent
- getEventHandlers
- getLatentEventHandles
- getLatentEventStatus
- removeEventHandler
- triggerEvent
- wasEventCancelled