OnClientElementDataChange: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
 
(7 intermediate revisions by 6 users not shown)
Line 1: Line 1:
{{Client event}}
{{Client event}}
__NOTOC__  
__NOTOC__  
This event is triggered whenever an element's ''[[element data]]'' is changed.
This event is triggered ''after'' an element's [[element data|data]] entry is changed. Such changes can be made on the client or the server using [[setElementData]].


==Parameters==
==Parameters==
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
string dataName
string theKey, var oldValue, var newValue
</syntaxhighlight>  
</syntaxhighlight>  


*'''dataName''': A string representing the element data that was changed
*'''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==
==Source==
The [[event system#Event source|source]] of this event is the [[element]] that had its element data changed
The [[event system#Event source|source]] of this event is the [[element]] whose [[element data]] changed.


==Example==  
==Example==  
This example tells the client whenever a player's "score" element data is changed.
This example tells the client whenever a player's "score" element data is changed.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
addEventHandler ( "onClientElementDataChange", getRootElement(),
function scoreChangeTracker(theKey, oldValue, newValue)
function ( dataName )
    if (getElementType(source) == "player") and (theKey == "score") then
if getElementType ( source ) == "player" and dataName == "score" then
        outputChatBox(getPlayerName(source).."'s new score is "..newValue.."!")
outputChatBox ( getPlayerName(source).."'s new score is "..getElementData ( source, "score".."!" )
    end
end
end
end )
addEventHandler("onClientElementDataChange", root, scoreChangeTracker)
</syntaxhighlight>
</syntaxhighlight>
[[pl:onClientElementDataChange]]
==See Also==
===Client element events===
{{Client_element_events}}
===Client event functions===
{{Client_event_functions}}

Latest revision as of 12:28, 8 October 2018

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.

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

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

Example

This example tells the client whenever a player's "score" element data is changed.

function scoreChangeTracker(theKey, oldValue, newValue)
    if (getElementType(source) == "player") and (theKey == "score") then
        outputChatBox(getPlayerName(source).."'s new score is "..newValue.."!")
    end
end
addEventHandler("onClientElementDataChange", root, scoreChangeTracker)

See Also

Client element events


Client event functions

Shared