{"name":"addMPEventHandler","title":"addMPEventHandler","type":"command","url":"https://community.bistudio.com/wiki/addMPEventHandler","revid":369855,"updated":"2024-10-16T13:52:05Z","groups":["Multiplayer","Event Handlers"],"status":"ok","games":{"arma2oa":"1.55","tkoh":"1.00","arma3":"0.50"},"since":"arma2oa 1.55","arma3_since":"0.50","locality":{"argument":"global","effect":"global"},"description":"Adds a multiplayer event handler (EH) to the given object and returns EH handle. See Event Handlers.\n\n> [!IMPORTANT]\n> A Multiplayer Event Handler is **not** saved in a save file and therefore will not be restored on load - use it accordingly.","syntaxes":[{"syntax":"object addMPEventHandler [type, expression]","params":[{"name":"object","type":"Object","description":"object to monitor","type_expr":"Object"},{"name":"type","type":"String","description":"event handler name","type_expr":"String"},{"name":"expression","type":"String or Code","description":"expression to execute.\nIf 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.\n\n> [!NOTE]\n> **Arma 3:** Since Arma 3 v.1.64 the EH handle is also stored in `_thisEventHandler` variable and is available during EH code execution.\n\n- Event Handler parameters are accessible via `_this`\n- The Event Handler type is available as `_thisEvent`\n- The Event Handler index is available as `_thisEventHandler`","type_expr":"String | Code"}],"returns":{"type":"Number","type_expr":"Number","description":"event handler index"},"form":"binary","left":{"text":"object"},"right":{"text":"[type, expression]"}}],"examples":[{"code":["_index = player addMPEventHandler [\"MPKilled\", { _this execVM \"playerKilled.sqf\"; }];"]}],"multiplayer":"Multiplayer EHs are added globally to every client and the server will fire on itself and every client upon event.\nThe 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.","see_also":["removeMPEventHandler","removeAllMPEventHandlers","getEventHandlerInfo"]}