OnAccountDataChange: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
 
(8 intermediate revisions by 5 users not shown)
Line 1: Line 1:
__NOTOC__
__NOTOC__
{{Server event}}
{{Server event}}
This event is triggered when an accounts data changes through [[setAccountData]]
This event is triggered when an accounts data changes through [[setAccountData]].


==Parameters==
==Parameters==
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
account theAccount, string theKey, var theValue
account theAccount, string theKey, string theValue
</syntaxhighlight>
</syntaxhighlight>


*'''theAccount''': The account getting its data changed
*'''theAccount''': the [[account]] that had data changed.
*'''theKey''': The key that is being changed
*'''theKey''': the [[string]] key that is being changed.
*'''theValue''': The value it is changing to
*'''theValue''': the value it is changing to.


==Source==
==Source==
The [[event system#Event source|source]] of this event is the root element.
The [[event system#Event source|source]] of this event is the [[root]] element.


==Example==
==Example==
This examples prevents the key of "level" being added or changed on every account
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)
function preventLevelChange(account, key, value)
Line 26: Line 26:
</syntaxhighlight>
</syntaxhighlight>


This examples logs every single account data change to server log
This examples logs every single account data change to server log.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
function preventLevelChange(account, key, value)
function preventLevelChange(account, key, value)
     if (wasEventCancelled()) then return end -- If the data change was aborted don't log it.
     if (wasEventCancelled()) then return end -- If the data change was aborted don't log it.
     outputServerLog(getAccountName(account).." key: "..key.." changed to: "..tostring(value))
     outputServerLog(getAccountName(account) .. " key: " .. key .. " changed to: " .. tostring(value))
end
end
addEventHandler("onAccountDataChange", root, preventLevelChange)
addEventHandler("onAccountDataChange", root, preventLevelChange)
</syntaxhighlight>
</syntaxhighlight>


{{See also/Server event|Server events}}
{{See also/Server event|Account events}}

Latest revision as of 02:50, 27 September 2018

This event is triggered when an accounts data changes through setAccountData.

Parameters

account theAccount, string theKey, string theValue
  • theAccount: the account that had data changed.
  • theKey: the string 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

Account events


Event functions