{"name":"addMPEventHandler","operator":null,"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","replaced_by":[],"games":[{"game":"arma2oa","name":"Arma 2: Operation Arrowhead","version":"1.55"},{"game":"tkoh","name":"Take On Helicopters","version":"1.00"},{"game":"arma3","name":"Arma 3","version":"0.50"}],"since":{"game":"arma2oa","name":"Arma 2: Operation Arrowhead","version":"1.55"},"arma3_since":"0.50","branch":null,"locality":{"argument":"global","effect":"global","server_exec":false},"exec":null,"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]","since":null,"effect":null,"exec":null,"params":[{"name":"object","type":"Object","optional":false,"default":null,"description":"object to monitor","types":["Object"],"since":null,"text":"object: Object - object to monitor"},{"name":"type","type":"String","optional":false,"default":null,"description":"event handler name","types":["String"],"since":null,"text":"type: String - event handler name"},{"name":"expression","type":"String or Code","optional":false,"default":null,"description":"expression to execute.\n\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`","types":["String","Code"],"since":null,"text":"expression: String or Code - expression to execute.\n\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`"}],"returns":{"type":"Number","types":["Number"],"description":"event handler index","text":"Number - event handler index"},"form":"binary","operator":null,"left":{"text":"object","types":["Object"]},"right":{"text":"[type, expression]","types":["Array"]}}],"examples":[{"text":"```sqf\n_index = player addMPEventHandler [\"MPKilled\", { _this execVM \"playerKilled.sqf\"; }];\n```","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.","problems":null,"aliases":[],"see_also":["removeMPEventHandler","removeAllMPEventHandlers","getEventHandlerInfo"],"notes":[],"categories":["Arma 2: Operation Arrowhead: New Scripting Commands","Arma 2: Operation Arrowhead: Scripting Commands","Arma 3: Scripting Commands","Command Group: Event Handlers","Command Group: Multiplayer","Introduced with Arma 2: Operation Arrowhead version 1.55","Scripting Commands","Scripting Commands: Global Effect","Take On Helicopters: Scripting Commands"]}