addMPEventHandler: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
m (Text replacement - " <h3 style="display:none">Notes</h3> <dl class="command_description"> <!-- Note Section BEGIN --> <!-- Note Section END --> </dl> " to "")
m (Text replacement - "(\|[pr][0-9]+ *= *[^-]+) *- *E([a-z])" to "$1 - e$2")
(22 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{Command|Comments=
{{RV|type=command


| arma2oa |Game name=
|game1= arma2oa
|version1= 1.55


|1.55|Game version=
|game2= tkoh
|version2= 1.00


|gr1 = Multiplayer |GROUP1=
|game3= arma3
|version3= 0.50


|gr2 = Event Handlers |GROUP2=
|gr1= Multiplayer


|arg= global |Multiplayer Arguments=
|gr2= Event Handlers


|eff= global |Multiplayer Effects=
|arg= global


| Adds MP event handler (EH) to the given object and returns EH handle.<br>
|eff= global
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>
{{Informative | For more information, see [[Arma_3:_Event_Handlers#Multiplayer_Event_Handlers|Event Handlers/addMPEventHandler]].}} |DESCRIPTION=


| object [[addMPEventHandler]] [type, expression]  |SYNTAX=
|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.}}


|p1= object: [[Object]] - object to monitor |Parameter1=
|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.


|p2= type: [[String]] - event handler name |Parameter2=
|s1= object [[addMPEventHandler]] [type, expression]


|p3= expression: [[String]] or [[Code]] - expression to execute |Parameter3=
|p1= object: [[Object]] - object to monitor


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


|x1= <code>_index = player [[addMPEventHandler]] ["MPKilled", { [[_this]] [[execVM]] "playerKilled.sqf"; }]; </code> |Example1=
|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.}}
* 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>


| [[:Category:Event Handlers|EventHandlers list]], [[removeMPEventHandler]], [[removeAllMPEventHandlers]] |SEEALSO=
|r1= [[Number]] - event handler index
}}


<h3 style="display:none">Bottom Section</h3>
|x1= <sqf>_index = player addMPEventHandler ["MPKilled", { _this execVM "playerKilled.sqf"; }];</sqf>


[[Category:Scripting Commands|{{uc:{{PAGENAME}}}}]]
|seealso= [[:Category:Event Handlers|EventHandlers List]] [[removeMPEventHandler]] [[removeAllMPEventHandlers]] [[getEventHandlerInfo]]
{{GameCategory|arma2|Scripting Commands}}
}}
{{GameCategory|arma3|Scripting Commands}}
{{GameCategory|tkoh|Scripting Commands}}
[[Category:Arma 2: Operation Arrowhead: New Scripting Commands List|{{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 14:06, 8 November 2023

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