AddElementDataSubscriber: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
(Remove obsolete Requirements section)
 
(4 intermediate revisions by 4 users not shown)
Line 1: Line 1:
{{Server function}}
{{Server function}}
__NOTOC__  
__NOTOC__  
{{New items|5.0157|1.5.7-9.20477|This function subscribes a [[player]] to specific [[element data]].
{{New items|3.0158|1.5.7-9.20477|This function subscribes a [[player]] to specific [[element data]].
This function is used together with [[setElementData]] in ''"subscribe"'' mode.
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.}}


==Syntax==  
==Syntax==  
Line 22: Line 24:
==Example==  
==Example==  
<section name="Server" class="server" show="true">
<section name="Server" class="server" show="true">
<syntaxhighlight>
<syntaxhighlight lang="lua">
TODO
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)
</syntaxhighlight>
</syntaxhighlight>
</section>
</section>


==See Also==
==See Also==
{{Element_functions}}
{{Element_functions|server}}

Latest revision as of 17:19, 7 November 2024

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

[[{{{image}}}|link=|]] 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.
[[{{{image}}}|link=|]] Note: Calling removeElementData or setElementData with other sync mode will automatically remove all subscribers of specified element data.

Syntax

bool addElementDataSubscriber ( element theElement, string key, player thePlayer )

OOP Syntax Help! I don't understand this!

Method: element:addDataSubscriber(...)
Counterpart: removeElementDataSubscriber


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

Returns true if the player was subscribed, false otherwise.

Example

Click to collapse [-]
Server
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