---
name: "addMPEventHandler"
type: command
status: ok
groups: ["Multiplayer", "Event Handlers"]
arma3_since: "0.50"
locality: {"argument": "global", "effect": "global", "server_exec": false}
source: https://community.bistudio.com/wiki/addMPEventHandler
revid: 369855
updated: 2024-10-16T13:52:05Z
---

# addMPEventHandler

*Command · Multiplayer, Event Handlers · Arma 3 v0.50 · introduced in Arma 2: Operation Arrowhead v1.55*

Locality: arguments **global** · effect **global**

## Description

Adds a multiplayer event handler (EH) to the given object and returns EH handle. See Event Handlers.

> [!IMPORTANT]
> A Multiplayer Event Handler is **not** saved in a save file and therefore will not be restored on load - use it accordingly.

## Syntax

```sqf
object addMPEventHandler [type, expression]
```

**Parameters:**

- `object`: [Object](../topics/Object.md) - object to monitor
- `type`: [String](../topics/String.md) - event handler name
- `expression`: [String](../topics/String.md) or [Code](../topics/Code.md) - 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.

  > [!NOTE]
  > **Arma 3:** Since Arma 3 v.1.64 the EH handle is also stored in `_thisEventHandler` variable and is available during EH code execution.

  - Event Handler parameters are accessible via `_this`
  - The Event Handler type is available as `_thisEvent`
  - The Event Handler index is available as `_thisEventHandler`

**Returns:** [Number](../topics/Number.md) - event handler index

## Examples

### Example 1

```sqf
_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.
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.

## See also

[removeMPEventHandler](../commands/removeMPEventHandler.md) · [removeAllMPEventHandlers](../commands/removeAllMPEventHandlers.md) · [getEventHandlerInfo](../commands/getEventHandlerInfo.md)

<sub>Source: [BI Community Wiki — addMPEventHandler](https://community.bistudio.com/wiki/addMPEventHandler) (revision 369855).</sub>
