OnElementDataChange: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
Line 13: | Line 13: | ||
==Global parameters== | ==Global parameters== | ||
*'''source''': The [[event system#Event source|source]] of this event is the [[element]] whose element data changed | *'''source''': The [[event system#Event source|source]] of this event is the [[element]] whose element data changed | ||
*'''client''': The [[event system#Event client|client]] global variable is set to the client that called [[setElementData]], or | *'''client''': The [[event system#Event client|client]] global variable is set to the client that called [[setElementData]], or nil if it was called on the server. | ||
==Cancelling== | ==Cancelling== | ||
Line 42: | Line 42: | ||
-- The client can only set 'special_thing' on its own player | -- The client can only set 'special_thing' on its own player | ||
if dataName == "special_thing" and client ~= source then | if dataName == "special_thing" and client ~= source then | ||
outputChatBox( "Illegal setting of "..tostring(dataName).."' by '"..tostring(getPlayerName(client)) ) | |||
outputChatBox( "Illegal setting of "..tostring(dataName | |||
setElementData( source, dataName, oldValue ) -- Set back the original value | setElementData( source, dataName, oldValue ) -- Set back the original value | ||
end | end |
Revision as of 03:56, 6 November 2013
This event is triggered when an elementdata entry for an element changes. A client can perform this change on the element or it can be done using setElementData.
Parameters
string theName, var theOldValue
- theName: The name of the element data entry that changed
- theOldValue: The old value of this entry before it changed. The new value can be accessed using getElementData ( source, theName ).
Global parameters
- source: The source of this event is the element whose element data changed
- client: The client global variable is set to the client that called setElementData, or nil if it was called on the server.
Cancelling
This event cannot be cancelled using cancelEvent. To reverse the effect, use setElementData with the old value. See Example.
Example
Click to collapse [-]
ServerThis example outputs a message to players when any of their element data values is changed.
function outputChange(dataName,oldValue) if getElementType(source) == "player" then -- check if the element is a player local newValue = getElementData(source,dataName) -- find the new value outputChatBox("Your element data '"..tostring(dataName).."' has changed from '"..tostring(oldValue).."' to '"..tostring(newValue).."'",source) -- output the change for the affected player end end addEventHandler("onElementDataChange",getRootElement(),outputChange)
Click to collapse [-]
ServerThis example checks and possibly reverses an element's data change.
function checkChange(dataName,oldValue) if client then -- The client can only set 'special_thing' on its own player if dataName == "special_thing" and client ~= source then outputChatBox( "Illegal setting of "..tostring(dataName).."' by '"..tostring(getPlayerName(client)) ) setElementData( source, dataName, oldValue ) -- Set back the original value end end end addEventHandler("onElementDataChange",getRootElement(),checkChange)
See Also
Element events
- onElementClicked
- onElementColShapeHit
- onElementColShapeLeave
- onElementDataChange
- onElementDestroy
- onElementDimensionChange
- onElementInteriorChange
- onElementModelChange
- onElementStartSync
- onElementStopSync
Event functions
- addEvent
- addEventHandler
- cancelEvent
- cancelLatentEvent
- getEventHandlers
- getLatentEventHandles
- getLatentEventStatus
- removeEventHandler
- triggerEvent
- wasEventCancelled