addElementDataSubscriber | Multi Theft Auto: Wiki Skip to content

addElementDataSubscriber

Client-side
Server-side
Shared

Pair: removeElementDataSubscriber

Manual Review Required

Please finish this page using the corresponding Old Wiki article. Go to Contribution guidelines for more information.


This function subscribes a player to specific element data. This function is used together with setElementData in "subscribe" mode.

Note

Before using this function you need to setup an initial value of element data in "subscribe" mode, otherwise the subscriber will not be added.

Note

Calling removeElementData or setElementData with other sync mode will automatically remove all subscribers of specified element data.

OOP Syntax Help! I don't understand this!

  • Method:element:addDataSubscriber(...)

Syntax

bool addElementDataSubscriber ( element theElement, string key, player thePlayer )
Required Arguments
  • theElement: The element you wish to subscribe the player to.
  • key: The key you wish to subscribe the player to.
  • thePlayer: The player you wish to subscribe.

Returns

  • bool: value

Returns true if the player was subscribed, false otherwise.

Code Examples

shared
addEventHandler("onVehicleEnter", getRootElement(), function(thePlayer, seat)
if seat==0 then -- if the player is a driver
addElementDataSubscriber(source, "id", thePlayer) -- subscribe the player to element
end
end)

See Also

Element Functions