addMPEventHandler: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
m (Text replacement - "Category:Arma 2: Operation Arrowhead: New Scripting Commands List" to "Category:Arma 2: Operation Arrowhead: New Scripting Commands")
(formatting)
Line 1: Line 1:
{{RV|type=command
{{RV|type=command


| arma2oa
|game1= arma2oa


|1.55
|version1= 1.55
 
|game1= tkoh
 
|version1= 1.00
 
|game1= arma3
 
|version1= 0.50


|gr1 = Multiplayer
|gr1 = Multiplayer
Line 13: Line 21:
|eff= global
|eff= global


| Adds MP event handler (EH) to the given object and returns EH handle.<br>
|descr= Adds a multiplayer event handler (EH) to the given object and returns EH handle.  
MP event handlers are added globally to every client on network in multiplayer and will fire on every client too upon event.
 
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 <tt>_this</tt> variable.<br>
<br>
Since Arma 3 v.1.63.137807 the EH handle is also stored in <tt>_thisEventHandler</tt> variable and is available during EH code execution.<br><br>
{{Feature | Informative | For more information, see [[Arma_3:_Event_Handlers#Multiplayer_Event_Handlers|Event Handlers/addMPEventHandler]].}}
{{Feature | Informative | For more information, see [[Arma_3:_Event_Handlers#Multiplayer_Event_Handlers|Event Handlers/addMPEventHandler]].}}


| object [[addMPEventHandler]] [type, expression]
|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]


|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
|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 <tt>_this</tt> variable.
{{Feature|arma3|Since Arma 3 v.1.64 the EH handle is also stored in <tt>_thisEventHandler</tt> variable and is available during EH code execution.}}


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


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


|seealso= [[:Category:Event Handlers|EventHandlers list]], [[removeMPEventHandler]], [[removeAllMPEventHandlers]]
|seealso= [[:Category:Event Handlers|EventHandlers List]] [[removeMPEventHandler]] [[removeAllMPEventHandlers]]
}}
}}
[[Category:Scripting Commands|{{uc:{{PAGENAME}}}}]]
{{GameCategory|arma2|Scripting Commands}}
{{GameCategory|arma3|Scripting Commands}}
{{GameCategory|tkoh|Scripting Commands}}
[[Category:Arma 2: Operation Arrowhead: New Scripting Commands|{{uc:{{PAGENAME}}}}]]
<!-- CONTINUE Notes -->
<dl class="command_description">
<dd class="notedate">Posted on May 8, 2015 - 12:24 (UTC)</dd>
<dt class="note">[[User:Killzone Kid|Killzone Kid]]</dt>
<dd class="note">
MP EHs are added on every PC and execute on every PC, apart from '''MPRespawn''', that only executes at the locality where unit respawns.
</dd>
</dl>
<!-- DISCONTINUE Notes -->

Revision as of 13:19, 17 March 2021

Hover & click on the images for description

Description

Description:
Adds a multiplayer event handler (EH) to the given object and returns EH handle.
For more information, see Event Handlers/addMPEventHandler.
Multiplayer:
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 EventHandlers List.
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 - Eventhandler index

Examples

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

Additional Information

See also:
EventHandlers List removeMPEventHandler removeAllMPEventHandlers

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