onElementDataChange | Multi Theft Auto: Wiki Skip to content

onElementDataChange

Client-side
Server-side
Shared

This event is triggered after an element's data entry is changed. Such changes can be made on the client or the server using setElementData.

These predefined variables are special in this event: client : The client global variable is set to the client that called setElementData , or nil if it was called on the server. sourceResource : The resource which changed the element data - nil , if client synced data, resource element otherwise.

Parameters

string theKey, var oldValue, var newValue
  • theKey: The name of the element data entry that has changed.
  • oldValue: The old value of this entry before it changed. See element data for a list of possible datatypes.
  • newValue: the new value of this entry after it changed. This will be equivalent to getElementData(source, theKey).

Source

element: The source of this event is the element whose element data changed.

Canceling

This event cannot be cancelled using cancelEvent. To reverse the effect, use setElementData with the old value. See Example.

Code Examples

server

This example outputs a message to players when any of their element data values is changed.

function outputChange(theKey, oldValue, newValue)
if (getElementType(source) == "player") then -- check if the element is a player
outputChatBox("Your element data '" .. tostring(theKey) .. "' has changed from '" .. tostring(oldValue) .. "' to '" .. tostring(newValue) .. "'", source) -- output the change for the affected player
end
end
addEventHandler("onElementDataChange", root, outputChange)

See Also

Element Functions