addMPEventHandler: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
m (Text replacement - "<code>([^ ]*)\[\[([a-zA-Z0-9_]+)\]\]([^ ]*)<\/code>" to "<code>$1$2$3</code>")
m (Text replacement - "{{Link|:Category:" to "{{Link|Category:")
 
(6 intermediate revisions by 2 users not shown)
Line 18: Line 18:
|eff= global
|eff= global


|descr= Adds a multiplayer event handler (EH) to the given object and returns EH handle.  
|descr= Adds a multiplayer event handler (EH) to the given object and returns EH handle. See {{Link|Category:Event Handlers|Event Handlers}}.
{{Feature|important|A Multiplayer Event Handler is '''not''' saved in a save file and therefore will not be restored on load - use it accordingly.}}


{{Feature | Informative | For more information, see [[Arma_3:_Event_Handlers#Multiplayer_Event_Handlers|Event Handlers/addMPEventHandler]].}}
|mp= Multiplayer EHs are added globally to every client and the server will fire on itself and every client upon event.
 
The only exception is the '''MPRespawn''' EH that one only fires where the respawned unit is local. Make sure to check the EHs' locality in {{Link|Category:Event Handlers|Event Handlers}} pages.
|mp= Multiplayer EHs are added globally to every client and the server and will fire on every client and server upon event. Only exception is the '''MPRespawn''' EH. That one only fires where the respawned unit is local. Make sure to check the locality of the EHs on [[:Category:Event Handlers|EventHandlers List]].


|s1= object [[addMPEventHandler]] [type, expression]
|s1= object [[addMPEventHandler]] [type, expression]


|p1= object: [[Object]] - Object to monitor
|p1= object: [[Object]] - object to monitor


|p2= type: [[String]] - Event handler name
|p2= type: [[String]] - event handler name


|p3= expression: [[String]] or [[Code]] - Expression to execute.<br>If EH has some data to return upon event (e.g. the "MPKilled" EH will return an array with 2 elements: the killed unit, and the killer), it is passed in {{hl|_this}} variable.
|p3= expression: [[String]] or [[Code]] - expression to execute.<br>
If EH has some data to return upon event (e.g. the "MPKilled" EH will return an array with 2 elements: the killed unit, and the killer), it is passed in {{hl|_this}} variable.
{{Feature|arma3|Since Arma 3 v.1.64 the EH handle is also stored in {{hl|_thisEventHandler}} variable and is available during EH code execution.}}
{{Feature|arma3|Since Arma 3 v.1.64 the EH handle is also stored in {{hl|_thisEventHandler}} variable and is available during EH code execution.}}
* Event Handler parameters are accessible via <sqf inline>_this</sqf>
* The Event Handler type is available as <sqf inline>_thisEvent</sqf>
* The Event Handler index is available as <sqf inline>_thisEventHandler</sqf>


|r1= [[Number]] - Eventhandler index
|r1= [[Number]] - event handler index


|x1= <code>_index = player addMPEventHandler ["MPKilled", { [[Magic Variables#this|_this]] execVM "playerKilled.sqf"; }];</code>
|x1= <sqf>_index = player addMPEventHandler ["MPKilled", { _this execVM "playerKilled.sqf"; }];</sqf>


|seealso= [[:Category:Event Handlers|EventHandlers List]] [[removeMPEventHandler]] [[removeAllMPEventHandlers]]
|seealso= [[:Category:Event Handlers|EventHandlers List]] [[removeMPEventHandler]] [[removeAllMPEventHandlers]] [[getEventHandlerInfo]]
}}
}}

Latest revision as of 14:52, 16 October 2024

Hover & click on the images for description

Description

Description:
Adds a multiplayer event handler (EH) to the given object and returns EH handle. See Event Handlers.
A Multiplayer Event Handler is not saved in a save file and therefore will not be restored on load - use it accordingly.
Multiplayer:
Multiplayer EHs are added globally to every client and the server will fire on itself and every client upon event. The only exception is the MPRespawn EH that one only fires where the respawned unit is local. Make sure to check the EHs' locality in Event Handlers pages.
Groups:
MultiplayerEvent Handlers

Syntax

Syntax:
object addMPEventHandler [type, expression]
Parameters:
object: Object - object to monitor
type: String - event handler name
expression: String or Code - expression to execute.
If EH has some data to return upon event (e.g. the "MPKilled" EH will return an array with 2 elements: the killed unit, and the killer), it is passed in _this variable.
Arma 3
Since Arma 3 v.1.64 the EH handle is also stored in _thisEventHandler variable and is available during EH code execution.
Return Value:
Number - event handler index

Examples

Example 1:
_index = player addMPEventHandler ["MPKilled", { _this execVM "playerKilled.sqf"; }];

Additional Information

See also:
EventHandlers List removeMPEventHandler removeAllMPEventHandlers getEventHandlerInfo

Notes

Report bugs on the Feedback Tracker and/or discuss them on the Arma Discord or on the Forums.
Only post proven facts here! Add Note