---
name: "Arma 3: Mission Event Handlers"
type: topic
aliases: ["Arma 3: Event Handlers/addMissionEventHandler"]
source: https://community.bistudio.com/wiki/Arma_3:_Mission_Event_Handlers
revid: 378631
updated: 2026-05-15T11:20:24Z
---

# Arma 3: Mission Event Handlers

Arma 3 v0.50 Local Effect

Mission event handlers are specific EHs that are anchored to the running mission and automatically removed when mission is over.
These events fire only on the machine where they have been added.

For all other available EHs see the [Event Handlers main page](../topics/Event_Handlers.md).

> [!NOTE]
> **OnUser...** mission event handlers used in combination with [getUserInfo](../commands/getUserInfo.md) provide a way to track server users from the very early stage of joining a server to the very last stage of leaving the server. All these event handlers are designed to be used server side and return unique user network id in [String](../topics/String.md) format as the first param. These ids could also be obtained via [getPlayerID](../commands/getPlayerID.md) and [allUsers](../commands/allUsers.md) script commands. There may be other params specific to each event. See:
>
> - [#OnUserConnected](../topics/Mission_Event_Handlers.md#onuserconnected)
> - [#OnUserDisconnected](../topics/Mission_Event_Handlers.md#onuserdisconnected)
> - [#OnUserClientStateChanged](../topics/Mission_Event_Handlers.md#onuserclientstatechanged)
> - [#OnUserAdminStateChanged](../topics/Mission_Event_Handlers.md#onuseradminstatechanged)
> - [#OnUserSelectedPlayer](../topics/Mission_Event_Handlers.md#onuserselectedplayer)
> - [#OnUserKicked](../topics/Mission_Event_Handlers.md#onuserkicked)

### Related Commands

- [addMissionEventHandler](../commands/addMissionEventHandler.md)
- [removeMissionEventHandler](../commands/removeMissionEventHandler.md)
- [removeAllMissionEventHandlers](../commands/removeAllMissionEventHandlers.md)

### Events

##### ActionTargetChanged (Arma 3 v2.22)

Executes when action target object changes under cursor. This event handler fires before user actions are processed and added to the player.

```sqf
addMissionEventHandler ["ActionTargetChanged", {
    params ["_newActionTarget", "_oldActionTarget"];
}];
```

- newActionTarget: [Object](../topics/Object.md)
- oldActionTarget: [Object](../topics/Object.md)

##### ArtilleryShellFired (Arma 3 v2.18)

Global Mission Event Handler. Executes each time a vehicle classified as artillery (has an artillery computer) fires a shell.

```sqf
addMissionEventHandler ["ArtilleryShellFired", {
    params ["_vehicle", "_weapon", "_ammo", "_gunner", "_instigator", "_artilleryTarget", "_targetPosition", "_shell"];
}];
```

- vehicle: [Object](../topics/Object.md) - artillery vehicle firing the shell
- weapon: [String](../topics/String.md) - weapon name
- ammo: [String](../topics/String.md) - ammo name
- gunner: [Object](../topics/Object.md) - gunner
- instigator: [Object](../topics/Object.md) - instigator
- artilleryTarget: [Object](../topics/Object.md) - artillery target object
- targetPosition: [Position](../topics/Position.md) - ground position the shell is aimed at
- shell: [Object](../topics/Object.md) - the projectile

##### BuildingChanged (Arma 3 v1.68)

Fired each time a building model changes, for example due to stages of destruction.

```sqf
addMissionEventHandler ["BuildingChanged", {
    params ["_from", "_to", "_isRuin"];
}];
```

- from: [Object](../topics/Object.md) - building it changes from
- to: [Object](../topics/Object.md) - building it changes to
- isRuin: [Boolean](../topics/Boolean.md) - [true](../commands/true.md) if changes to ruins

##### CommandModeChanged (Arma 3 v1.58)

Executes assigned code when user switches to/from High Command mode (<kbd>LShift</kbd>+<kbd>Space</kbd>). Stackable version of [onCommandModeChanged](../commands/onCommandModeChanged.md).

```sqf
addMissionEventHandler ["CommandModeChanged", {
    params ["_isHighCommand", "_isForced"];
}];
```

- isHighCommand: [Boolean](../topics/Boolean.md) - same as `_isHighCommand` param
- isForced: [Boolean](../topics/Boolean.md) - [true](../commands/true.md) if command mode was forced

##### ControlsShifted (Arma 3 v1.00)

Triggers when control of a vehicle is shifted (pilot->co-pilot, co-pilot->pilot), usually when user performs an [action](../commands/action.md) such as [TakeVehicleControl](../topics/Actions.md#takevehiclecontrol), [SuspendVehicleControl](../topics/Actions.md#suspendvehiclecontrol), [UnlockVehicleControl](../topics/Actions.md#unlockvehiclecontrol), [LockVehicleControl](../topics/Actions.md#lockvehiclecontrol), or when [enableCopilot](../commands/enableCopilot.md) command is used. This event handler will always fire on the PC where [action](../commands/action.md) is triggered as well as where the vehicle is [local](../topics/Multiplayer_Scripting.md#locality) at the time. When control of the vehicle is shifted, the locality of the vehicle changes to the locality of the new controller. Since Arma 3 v1.96 this EH is extended with additional params.

```sqf
addMissionEventHandler ["ControlsShifted", {
    params ["_newController", "_oldController", "_vehicle", "_copilotEnabled", "_controlsUnlocked"];
}];
```

- newController: [Object](../topics/Object.md) - unit currently controlling the vehicle
- oldController: [Object](../topics/Object.md) - unit previously controlling the vehicle
- vehicle: [Object](../topics/Object.md) - the vehicle for which controls shifted
- copilotEnabled: [Boolean](../topics/Boolean.md) - [true](../commands/true.md) if copilot is enabled
- controlsUnlocked: [Boolean](../topics/Boolean.md) - [true](../commands/true.md) if controls are unlocked

##### DisplayOpened (Arma 3 v2.22)

Executes when any display is opened.

```sqf
addMissionEventHandler ["DisplayOpened", {
    params ["_display", "_configClass"];
}];
```

- display: [Display](../topics/Display.md)
- configClass: [Config](../topics/Config.md)

##### Draw2D (Arma 3 v2.18)

Runs after all UI has been drawn. Runs the EH code each frame in unscheduled environment. Client side EH only (presence of UI).
Will stop executing when UI loses focus (<kbd>Alt</kbd>+<kbd>Tab</kbd> for example). Usually used with [drawIcon](../commands/drawIcon.md).

```sqf
addMissionEventHandler ["Draw2D", {
    // no params
}];
```

##### Draw3D (Arma 3 v0.50)

Runs the EH code each frame in unscheduled environment. Client side EH only (presence of UI).
Will stop executing when UI loses focus (<kbd>Alt</kbd>+<kbd>Tab</kbd> for example). Usually used with [drawIcon3D](../commands/drawIcon3D.md), [drawLine3D](../commands/drawLine3D.md).

```sqf
addMissionEventHandler ["Draw3D", {
    // no params
}];
```

##### Drowned (Arma 3 v2.14)

Runs when a vehicle gets drowned (the vehicle is submerged below 'maxFord' for longer than 'waterResistance'). This will cause engine damage and for some vehicles that will render engine unusable until the vehicle/engine is fully repared. Some vehicles can drown but would still be recoverable as they wouldn't be destroyed. The event handler will also fire when vehicle is removed from water, in which case 'drowned' param will change to [false](../commands/false.md). To check if the engine was damaged by water use [waterDamaged](../commands/waterDamaged.md) command.

```sqf
addMissionEventHandler ["Drowned", {
    params ["_vehicle", "_drowned"];
}];
```

##### EachFrame (Arma 3 v1.58)

Executes assigned code each frame. Stackable version of [onEachFrame](../commands/onEachFrame.md).

```sqf
addMissionEventHandler ["EachFrame", {
    // no params
}];
```

##### Ended (Arma 3 v0.50)

Triggered when mission ends, either using trigger of type "End", [endMission](../commands/endMission.md) command, [BIS_fnc_endMission](../functions/BIS_fnc_endMission.md) function or ENDMISSION cheat.

```sqf
addMissionEventHandler ["Ended", {
    params ["_endType"];
}];
```

- endType: [String](../topics/String.md) - mission end type. Used in Debriefing among other things

##### MPEnded (Arma 3 v1.60)

Triggered when the server switches off from "playing" state (mission ends, server closes, etc.) It's only for MP games, it is called on server and also on clients. It is not called on clients when client disconnects from server (and mission continues). This EH has no arguments passed to the code.

```sqf
addMissionEventHandler ["MPEnded", {
    // no params
}];
```

If client code must be executed on disconnect, this code can be used instead:

```sqf
0 spawn
{
    waitUntil { !isNull findDisplay 46 };
    findDisplay 46 displayAddEventHandler ["Unload",
    {
        // code here gets executed on the client at end of mission, whether due to player abort, loss of connection, or mission ended by server
        // might not work on headless clients
    }];
};
```

##### EntityCreated (Arma 3 v2.10)

Triggered when an entity is created.

> [!NOTE]
> Unlike most event handlers, the argument is entity [Object](../topics/Object.md) and not an array containing the entity. However, it is recommended to use [params](../commands/params.md) to make sure the code remains compatible in case the event arguments are expanded in the future.

> [!IMPORTANT]
> This event is called before variable namespace is copied to **remote** respawning entity, keep this in mind so your [setVariable](../commands/setVariable.md)s are not overwritten in the next frame. [EntityRespawned](../topics/Mission_Event_Handlers.md#entityrespawned) always fires after variable namespace is copied to new entity regardless of locality.

```sqf
addMissionEventHandler ["EntityCreated", {
    params ["_entity"];
}];
```

##### EntityDeleted (Arma 3 v2.18)

Triggered when an entity is deleted. It only triggers for objects that support the "Deleted" event handler, such as vehicles, soldiers, animals, and houses. Simple objects for example are not supported.

> [!NOTE]
> Unlike most event handlers, the argument is entity [Object](../topics/Object.md) and not an array containing the entity. However, it is recommended to use [params](../commands/params.md) to make sure the code remains compatible in case the event arguments are expanded in the future.

```sqf
addMissionEventHandler ["EntityDeleted", {
    params ["_entity"];
}];
```

##### EntityKilled (Arma 3 v1.56)

Triggered when an entity is killed.

```sqf
addMissionEventHandler ["EntityKilled", {
    params ["_unit", "_killer", "_instigator", "_useEffects"];
}];
```

- unit: [Object](../topics/Object.md) - entity that was killed
- killer: [Object](../topics/Object.md) - the killer (vehicle or person)
- Arma 3 v1.66 instigator: [Object](../topics/Object.md) - person who pulled the trigger
- Arma 3 v1.68 useEffects: [Boolean](../topics/Boolean.md) - same as *useEffects* in [setDamage](../commands/setDamage.md) alt syntax

---

It's worth noting that *instigator* param is [objNull](../commands/objNull.md) during road kill. To work around this issue try:

```sqf
addMissionEventHandler ["EntityKilled", {
    params ["_killed", "_killer", "_instigator"];
    if (isNull _instigator) then { _instigator = UAVControl vehicle _killer select 0 }; // UAV/UGV player operated road kill
    if (isNull _instigator) then { _instigator = _killer }; // player driven vehicle road kill
    hint format ["Killed By %1", name _instigator];
}];
```

##### EntityRespawned (Arma 3 v1.56)

Triggered when an entity is respawned.

```sqf
addMissionEventHandler ["EntityRespawned", {
    params ["_newEntity", "_oldEntity"];
}];
```

- newEntity: [Object](../topics/Object.md) - respawned entity
- oldEntity: [Object](../topics/Object.md) - corpse/wreck

##### ExtensionCallback (Arma 3 v1.96)

Triggered when an [extension](../commands/callExtension.md) calls provided function pointer with 3 params.

```sqf
addMissionEventHandler ["ExtensionCallback", {
    params ["_name", "_function", "_data"];
}];
```

- name: [String](../topics/String.md) - user provided param
- function: [String](../topics/String.md) - user provided param
- data: [String](../topics/String.md) - user provided param

##### GroupCreated (Arma 3 v2.04)

Triggered when a [Group](../topics/Group.md) is created. Note that the group contains **no** units at that point!

```sqf
addMissionEventHandler ["GroupCreated", {
    params ["_group"];
}];
```

- group: [Group](../topics/Group.md) - the created group

##### GroupDeleted (Arma 3 v2.04)

Triggered when a [Group](../topics/Group.md) is [manually](../commands/deleteGroup.md) or [automatically](../commands/deleteGroupWhenEmpty.md) deleted.

```sqf
addMissionEventHandler ["GroupDeleted", {
    params ["_group"];
}];
```

- group: [Group](../topics/Group.md) - the deleted group

##### GroupIconClick (Arma 3 v1.58)

Executes assigned code when user clicks on the HC group icon on the map. If [groupIconSelectable](../commands/groupIconSelectable.md) is [true](../commands/true.md), LMB clicking (firing) at the HC group icon on the HUD will also trigger the event. To set group icon selectable use [setGroupIconsSelectable](../commands/setGroupIconsSelectable.md). Stackable version of [onGroupIconClick](../commands/onGroupIconClick.md).

```sqf
addMissionEventHandler ["GroupIconClick", {
    params [
        "_is3D", "_group", "_waypointId",
        "_mouseButton", "_posX", "_posY",
        "_shift", "_control", "_alt"
    ];
}];
```

- is3D: [Boolean](../topics/Boolean.md) - [true](../commands/true.md) if HUD icon, [false](../commands/false.md) if main map icon
- group: [Group](../topics/Group.md) - group the icon belonds to
- waypointId: [Number](../topics/Number.md) - waypoint ID
- mouseButton: [Number](../topics/Number.md) - mouse button: 0 - <kbd>LMB</kbd>, 1 - <kbd>RMB</kbd> (only applicable to IconClick)
- posX: [Number](../topics/Number.md) - screen X of the mouse
- posY: [Number](../topics/Number.md) - screen Y of the mouse
- shift: [Boolean](../topics/Boolean.md) - [true](../commands/true.md) if <kbd>Shift</kbd> key was pressed
- ctrl: [Boolean](../topics/Boolean.md) - [true](../commands/true.md) if <kbd>Ctrl</kbd> key was pressed
- alt: [Boolean](../topics/Boolean.md) - [true](../commands/true.md) if <kbd>Alt</kbd> key was pressed

##### GroupIconOverEnter (Arma 3 v1.58)

**Continuously** executes assigned code when user hovers with pointer over the HC group icon, either on the HUD or the main map. [groupIconSelectable](../commands/groupIconSelectable.md) must be set to [true](../commands/true.md) for this EH to work at all. To set group icon selectable use [setGroupIconsSelectable](../commands/setGroupIconsSelectable.md). When EH fires over the HUD icon, X and Y coordinates will change depending on the position of the pointer in relation to the icon area. When over main map, the X and Y do not change and indicate icon center. Stackable version of [onGroupIconOverEnter](../commands/onGroupIconOverEnter.md).

```sqf
addMissionEventHandler ["GroupIconOverEnter", {
    params [
        "_is3D", "_group", "_waypointId",
        "_posX", "_posY",
        "_shift", "_control", "_alt"
    ];
}];
```

- is3D: [Boolean](../topics/Boolean.md) - [true](../commands/true.md) if HUD icon, [false](../commands/false.md) if main map icon
- group: [Group](../topics/Group.md) - group the icon belonds to
- waypointId: [Number](../topics/Number.md) - waypoint ID
- posX: [Number](../topics/Number.md) - screen X of the mouse
- posY: [Number](../topics/Number.md) - screen Y of the mouse
- shift: [Boolean](../topics/Boolean.md) - [true](../commands/true.md) if <kbd>Shift</kbd> key was pressed
- ctrl: [Boolean](../topics/Boolean.md) - [true](../commands/true.md) if <kbd>Ctrl</kbd> key was pressed
- alt: [Boolean](../topics/Boolean.md) - [true](../commands/true.md) if <kbd>Alt</kbd> key was pressed

##### GroupIconOverLeave (Arma 3 v1.58)

Executes assigned code when user moves the pointer away from HC group icon it was over. Fires either for on the HUD icons or the main map HC icons. [groupIconSelectable](../commands/groupIconSelectable.md) must be set to [true](../commands/true.md) for this EH to work at all. To set group icon selectable use [setGroupIconsSelectable](../commands/setGroupIconsSelectable.md). Stackable version of [onGroupIconOverLeave](../commands/onGroupIconOverLeave.md).

```sqf
addMissionEventHandler ["GroupIconOverLeave", {
    params [
        "_is3D", "_group", "_waypointId",
        "_posX", "_posY",
        "_shift", "_control", "_alt"
    ];
}];
```

- is3D: [Boolean](../topics/Boolean.md) - [true](../commands/true.md) if HUD icon, [false](../commands/false.md) if main map icon
- group: [Group](../topics/Group.md) - group the icon belonds to
- waypointId: [Number](../topics/Number.md) - waypoint ID
- posX: [Number](../topics/Number.md) - screen X of the mouse
- posY: [Number](../topics/Number.md) - screen Y of the mouse (Y is always 0 when leaving HUD icon for some reason)
- shift: [Boolean](../topics/Boolean.md) - [true](../commands/true.md) if <kbd>Shift</kbd> key was pressed
- ctrl: [Boolean](../topics/Boolean.md) - [true](../commands/true.md) if <kbd>Ctrl</kbd> key was pressed
- alt: [Boolean](../topics/Boolean.md) - [true](../commands/true.md) if <kbd>Alt</kbd> key was pressed

##### HandleAccTime (Arma 3 v1.90)

Fires when user changes time acceleration with +/- keys in SP or [setAccTime](../commands/setAccTime.md) command. If the code returns [true](../commands/true.md) the on-screen message confirming the change is not displayed. Doesn't fire if desired value is already set.

```sqf
addMissionEventHandler ["HandleAccTime", {
    params ["_currentTimeAcc", "_prevTimeAcc", "_messageSuppressed"];
}];
```

- currentTimeAcc: [Number](../topics/Number.md) - current value
- prevTimeAcc: [Number](../topics/Number.md) - previous value
- messageSuppressed: [Boolean](../topics/Boolean.md) - [true](../commands/true.md) if on-screen message was suppressed

##### HandleChatMessage (Arma 3 v2.00)

Fires when a message is received, before adding it to the chat feed. Fires clientside.

> [!NOTE]
> - On a dedicated server and headless client it fires only for global (channel 0) and system messages (channel 16).
> - The HandleChatMessage EH can be used to disable/modify system messages like "Player NAME connecting/is losing connection".

> [!IMPORTANT]
> Does not trigger for any of the chat related script command such as [systemChat](../commands/systemChat.md), [sideChat](../commands/sideChat.md), or other chat commands.

The output message could be overridden:
- Return [true](../commands/true.md) to block incoming chat message from being added to the chat feed.
- Return [String](../topics/String.md) to replace the chat message content but not the sender name.
- Return [Array](../topics/Array.md) [from, text] to replace both the chat message content and the the sender's name.

> [!IMPORTANT]
> Only the last added HandleChatMessage EH with override will be used to override the message.

> [!WARNING]
> Do not put any of the chat related script command such as [systemChat](../commands/systemChat.md), [sideChat](../commands/sideChat.md), etc in this EH code as it would naturally cause recursion and the game will freeze.

```sqf
addMissionEventHandler ["HandleChatMessage", {
    params ["_channel", "_owner", "_from", "_text", "_person", "_name", "_strID", "_forcedDisplay", "_isPlayerMessage", "_sentenceType", "_chatMessageType", "_params"];
}];
```

- channel: [Number](../topics/Number.md) - see [radio channel indices](../topics/Description.ext.md#disablechannels) (16 for system chat message for example)
- owner: [Number](../topics/Number.md) - [owner](../commands/owner.md) id of the sender:
  - in SP: 0
  - in MP with no sender: [clientOwner](../commands/clientOwner.md)
  - in MP with sender: sender's [clientOwner](../commands/clientOwner.md), or if AI - creator id part of [netId](../commands/netId.md) of the AI
- from: [String](../topics/String.md) - sender's formatted name as appeared on the chat
- text: [String](../topics/String.md) - the chat message
- person: [Object](../topics/Object.md) - sender's object
- name: [String](../topics/String.md) - sender's [name](../commands/name.md), could be different from `from`
- strID: [String](../topics/String.md) - sender's network player ID (marker id):
  - "-1": means not available
  - "0": means [isPlayer](../commands/player.md) in SP
  - "1": means AI in SP or MP
  - >1: [getPlayerID](../commands/getPlayerID.md) in MP
- forcedDisplay: [Boolean](../topics/Boolean.md) - if the message should be displayed when the chat list is disabled (when [enableRadio](../commands/enableRadio.md) is set to [false](../commands/false.md) radio protocol messages won't display)
- isPlayerMessage: [Boolean](../topics/Boolean.md) - if the message is addressed to [player](../commands/player.md)
- sentenceType: [Number](../topics/Number.md) - 0: Normal type, 1: Protocol type
- chatMessageType: [Number](../topics/Number.md) - 0: Generic type, 1: SimpleMove type, 2: KillConfirmation type
- params: [Array](../topics/Array.md) of [String](../topics/String.md)s - sentence parameters, if any

##### HandleDisconnect (Arma 3 v1.32 Server Execution)

Triggered right after a player disconnects from the game, more accurately when a player-controlled unit changes ownership due to the owning player being disconnected (disconnected player information is no available through e.g [getUserInfo](../commands/getUserInfo.md) anymore).
Similar to the [#PlayerDisconnected](../topics/Mission_Event_Handlers.md#playerdisconnected) event but contains the unit occupied by the player before their disconnection.
Must be added on the server and triggers only on the server.

> [!IMPORTANT]
> A player disconnecting while not controlling a unit (not spawned, deleted unit, etc) does **not** trigger this event.

```sqf
addMissionEventHandler ["HandleDisconnect", {
    params ["_unit", "_id", "_uid", "_name"];
    true;
}];
```

- unit: [Object](../topics/Object.md) - unit formerly occupied by player
- id: [Number](../topics/Number.md) - same as _id in [onPlayerDisconnected](../commands/onPlayerDisconnected.md)
- uid: [String](../topics/String.md) - same as _uid in [onPlayerDisconnected](../commands/onPlayerDisconnected.md)
- name: [String](../topics/String.md) - same as _name in [onPlayerDisconnected](../commands/onPlayerDisconnected.md)
**Override**: if this EH code returns [true](../commands/true.md), the unit, previously occupied by player, gets transferred to the server, becomes AI and continues to live, even with [description.ext](../topics/Description.ext.md) param `disabledAI = 1;`.

##### HCGroupSelectionChanged (Arma 3 v1.58)

Executes assigned code when user selects available HC group (`F1, F2…`). Stackable version of [onHCGroupSelectionChanged](../commands/onHCGroupSelectionChanged.md).

```sqf
addMissionEventHandler ["HCGroupSelectionChanged", {
    params ["_group", "_isSelected"];
}];
```

- group: [Group](../topics/Group.md) - group selected (same as `_group` param)
- isSelected: [Boolean](../topics/Boolean.md) - [true](../commands/true.md) if selected (same as `_isSelected` param)

##### Loaded (Arma 3 v0.50)

Triggered when mission is loaded from save.

> [!WARNING]
> "Loaded" event handler should be added BEFORE the mission is loaded from save. Placing it in a [function](../topics/Functions_Library.md) with preInit = 1; usually does the trick.

```sqf
addMissionEventHandler ["Loaded", {
    params ["_saveType"];
}];
```

- savingType: [String](../topics/String.md) - one of "autosaveold", "autosave", "save", "save2", "save3", "save4", "save5", "save6", "continue" or "".
  - "save" - custom save, achieved by pressing SAVE button in the pause menu
  - "autosave" - automatic checkpoint, saved using [saveGame](../commands/saveGame.md) command
  - "continue" - saved when leaving a mission to the main menu

##### Map (Arma 3 v1.62)

Triggered when map is opened or closed either by user action or script command [openMap](../commands/openMap.md).

```sqf
addMissionEventHandler ["Map", {
    params ["_mapIsOpened", "_mapIsForced"];
}];
```

- mapIsOpened: [Boolean](../topics/Boolean.md) - [true](../commands/true.md) if map is opened
- mapIsForced: [Boolean](../topics/Boolean.md) - [true](../commands/true.md) if map is forced

##### MapSingleClick (Arma 3 v1.58)

Executes when the player clicks anywhere on the main map. Stackable version of [onMapSingleClick](../commands/onMapSingleClick.md) with the limitation that it does not have the ability to override the click (e.g. to prevent the player from placing the [custom waypoint](../commands/customWaypointPosition.md) with <kbd>LShift</kbd>+<kbd>LMB</kbd>). Since the introduction of `_thisArgs` for [addMissionEventHandler](../commands/addMissionEventHandler.md) in Arma 3 v2.04, this EH also supports custom arguments (just like [onMapSingleClick](../commands/onMapSingleClick.md)).

```sqf
addMissionEventHandler ["MapSingleClick", {
    params ["_units", "_pos", "_alt", "_shift"];
}];
```

- units: [Array](../topics/Array.md) - leader selected units, same as [groupSelectedUnits](../commands/groupSelectedUnits.md) (same as [onMapSingleClick](../commands/onMapSingleClick.md)'s `_units` variable)
- pos: [Array](../topics/Array.md) - world [Position3D](../topics/Position.md#introduction) of the click in format `[x, y, 0]` (same as [onMapSingleClick](../commands/onMapSingleClick.md)'s `_pos` variable)
- alt: [Boolean](../topics/Boolean.md) - [true](../commands/true.md) if <kbd>Alt</kbd> key was pressed (same as [onMapSingleClick](../commands/onMapSingleClick.md)'s `_alt` variable)
- shift: [Boolean](../topics/Boolean.md) - [true](../commands/true.md) if <kbd>Shift</kbd> key was pressed (same as [onMapSingleClick](../commands/onMapSingleClick.md)'s `_shift` variable)

##### MarkerCreated (Arma 3 v2.02)

Executes when a marker is created either by a user or via script command.

```sqf
addMissionEventHandler ["MarkerCreated", {
    params ["_marker", "_channelNumber", "_owner", "_local"];
}];
```

- marker: [String](../topics/String.md) - the name of the created marker, can be used with the marker commands
- channelNumber: [Number](../topics/Number.md) - channel in which the marker was created
- owner: [Object](../topics/Object.md) - player that created the marker or [objNull](../commands/objNull.md)
- Arma 3 v2.04 local: [Boolean](../topics/Boolean.md) - [true](../commands/true.md) if the event originated locally, [false](../commands/false.md) if it came over the network

##### MarkerDeleted (Arma 3 v2.02)

Executes immediately before a marker is deleted either by a user or via script command.

```sqf
addMissionEventHandler ["MarkerDeleted", {
    params ["_marker", "_local", "_deleter"];
}];
```

- marker: [String](../topics/String.md) - the name of the deleted marker
- Arma 3 v2.04 local: [Boolean](../topics/Boolean.md) - [true](../commands/true.md) if the event originated locally, [false](../commands/false.md) if it came over the network
- Arma 3 v2.20 deleter: [Object](../topics/Object.md) - the player/curator unit that deleted the marker

##### MarkerUpdated (Arma 3 v2.02)

Executes when a marker is changed.

> [!WARNING]
> Changing the marker in the EH code will lead to an infinite loop and the game will crash!

```sqf
addMissionEventHandler ["MarkerUpdated", {
    params ["_marker", "_local"];
}];
```

- marker: [String](../topics/String.md) - the name of the marker
- Arma 3 v2.04 local: [Boolean](../topics/Boolean.md) - [true](../commands/true.md) if the event originated locally, [false](../commands/false.md) if it came over the network

##### OnUserConnected (Arma 3 v2.06 Server Execution)

Executes assigned code on user joining server.

```sqf
addMissionEventHandler ["OnUserConnected", {
    params ["_networkId", "_clientStateNumber", "_clientState"];
}];
```

- networkId: [String](../topics/String.md) - user network id (see [getPlayerID](../commands/getPlayerID.md), [allUsers](../commands/allUsers.md))
- clientStateNumber: [Number](../topics/Number.md) - client state number (see [getClientStateNumber](../commands/getClientStateNumber.md)) - always 1
- clientState: [String](../topics/String.md) - client state (see [getClientState](../commands/getClientState.md)) - always "CREATED"

##### OnUserDisconnected (Arma 3 v2.06 Server Execution)

Executes assigned code on user leaving server.

```sqf
addMissionEventHandler ["OnUserDisconnected", {
        params ["_networkId", "_clientStateNumber", "_clientState"];
}];
```

- networkId: [String](../topics/String.md) - user network id (see [getPlayerID](../commands/getPlayerID.md), [allUsers](../commands/allUsers.md))
- clientStateNumber: [Number](../topics/Number.md) - client state number (see [getClientStateNumber](../commands/getClientStateNumber.md)) - always 0
- clientState: [String](../topics/String.md) - client state (see [getClientState](../commands/getClientState.md)) - always "NONE"

##### OnUserClientStateChanged (Arma 3 v2.06 Server Execution)

Executes assigned code for every stage of user client state change.

```sqf
addMissionEventHandler ["OnUserClientStateChanged", {
    params ["_networkId", "_clientStateNumber", "_clientState"];
}];
```

- networkId: [String](../topics/String.md) - user network id (see [getPlayerID](../commands/getPlayerID.md), [allUsers](../commands/allUsers.md))
- clientStateNumber: [Number](../topics/Number.md) - client state number (see [getClientStateNumber](../commands/getClientStateNumber.md))
- clientState: [String](../topics/String.md) - client state (see [getClientState](../commands/getClientState.md))

##### OnUserAdminStateChanged (Arma 3 v2.06 Server Execution)

Executes assigned code after user logs in, gets voted in or logs out as admin.

```sqf
addMissionEventHandler ["OnUserAdminStateChanged", {
    params ["_networkId", "_loggedIn", "_votedIn"];
}];
```

- networkId: [String](../topics/String.md) - user network id (see [getPlayerID](../commands/getPlayerID.md), [allUsers](../commands/allUsers.md))
- loggedIn: [Boolean](../topics/Boolean.md) - [true](../commands/true.md) if user logged in or got voted in as admin, [false](../commands/false.md) if logged out (see [admin](../commands/admin.md))
- votedIn: [Boolean](../topics/Boolean.md) - [true](../commands/true.md) if user got voted in as admin, [false](../commands/false.md) otherwise (see [admin](../commands/admin.md))

##### OnUserSelectedPlayer (Arma 3 v2.06 Server Execution)

Executes assigned code after player object is selected for user to take over control, the ownership information is broadcast and request to sync is made but the object is still owned by previous owner for a short time.

```sqf
addMissionEventHandler ["OnUserSelectedPlayer", {
        params ["_networkId", "_playerObject", "_attempts"];
}];
```

- networkId: [String](../topics/String.md) - user network id (see [getPlayerID](../commands/getPlayerID.md), [allUsers](../commands/allUsers.md))
- playerObject: [Object](../topics/Object.md) - player object to be controlled by the user (see [player](../commands/player.md), [selectPlayer](../commands/selectPlayer.md))
- Arma 3 v2.18 attempts: [Number](../topics/Number.md) - how many times server was trying to obtain non-null playerObject. Current threshold after which the event will fire anyway is 50.

> [!IMPORTANT]
> This is the earliest the player object is known when player joins the server, but it is not local to the user yet, so there is a wait time depending on network connection. When player respawns, the unit created on the client and so it might take a while before server has valid player object. From Arma 3 v2.18 the server will pospone this event until the object is not null, or until it tried 50 times, whichever is earlier. The best approach to handle this matter and get notified about completion of the transfer of the ownership is to use ["Local"](../topics/Event_Handlers.md#local) entity event handler, like so:
>
> ```sqf
> addMissionEventHandler ["OnUserSelectedPlayer", {
>     params ["_networkId", "_playerObject", "_attempts"];
>     _playerObject addEventHandler ["Local",
>     {
>         params ["_player"];
>         _player removeEventHandler ["Local", _thisEventHandler];
>         // code to handle _player
>     }];
> }];
> ```
>
> Note that the player object would change locality again if the user goes to lobby.

##### OnUserKicked (Arma 3 v2.06 Server Execution)

Executes assigned code after after a user has been kicked from the server providing kick reason. The possible values for 'kickTypeNumber' and 'kickType' are:
0 : `"TIMEOUT"`, 1 : `"DISCONNECTED"`, 2 : `"KICKED"`, 3 : `"BANNED"`, 4 : `"MISSING ADDON"`, 5 : `"BAD CD KEY"`, 6 : `"CD KEY IN USE"`, 7 : `"SESSION LOCKED"`, 8 : `"BATTLEYE"`, 9 : `"STEAM CHECK"`, 10 : `"DLC CONTENT"`, 11 : `"GS TIMEOUT"`, 12 : `"SCRIPT"`, 13 : `"OTHER"`

```sqf
addMissionEventHandler ["OnUserKicked", {
    params ["_networkId", "_kickTypeNumber", "_kickType", "_kickReason", "_kickMessageIncReason"];
}];
```

- networkId: [String](../topics/String.md) - user network id (see [getPlayerID](../commands/getPlayerID.md), [allUsers](../commands/allUsers.md))
- kickTypeNumber: [Number](../topics/Number.md) - kick type number (see above)
- kickType: [String](../topics/String.md) - kick type (see above)
- kickReason: [String](../topics/String.md) - reason given for the kick by the admin or by other means
- kickMessageIncReason: [String](../topics/String.md) - formatted engine message including the given reason

##### PlayerConnected (Arma 3 v1.58 Server Execution)

Executes assigned code when client joins the mission in MP. Stackable version of [onPlayerConnected](../commands/onPlayerConnected.md).

```sqf
addMissionEventHandler ["PlayerConnected", {
    params ["_id", "_uid", "_name", "_jip", "_owner", "_idStr"];
}];
```

- id: [Number](../topics/Number.md) - unique DirectPlay ID (very large number). It is also the same id used for user placed markers
- uid: [String](../topics/String.md) - [getPlayerUID](../commands/getPlayerUID.md) of the joining client. The same as Steam ID
- name: [String](../topics/String.md) - [profileName](../commands/profileName.md) of the joining client
- jip: [Boolean](../topics/Boolean.md) - [didJIP](../commands/didJIP.md) of the joining client
- owner: [Number](../topics/Number.md) - [owner](../commands/owner.md) id of the joining client
- idStr: [String](../topics/String.md) - same as `_id` but in string format, so it can be exactly compared to [user marker](../commands/allMapMarkers.md) ids

> [!NOTE]
> **0** and **1** are special values:
> - **0** means **everyone** (including the server)
> - **1** means **current machine** but **is not implemented** and should **not** be used.

If a dedicated server was started without '-autoInit' option and this EH was created on server, on first GUI client this EH also fires against server, but after first client.
In mission's `initServer.sqf`:

```sqf
addMissionEventHandler ["PlayerConnected", {
    diag_log "Client connected";
    diag_log _this;
}];
```

In RPT:
 2016/12/16, 15:39:09 "Client connected"
 2016/12/16, 15:39:09 [1.51343e+009,"7xxxxxxxxxxxxxxx1","longbow",false,3,"1513430065"]
 2016/12/16, 15:39:34  Mission id: 5071d20b183e9580d0ee4f95f413ca18681d6165
 2016/12/16, 15:39:34 "Client connected"
 2016/12/16, 15:39:34 [2,"","__SERVER__",false,2,"2"]

That happens only for GUI clients, if HC client connects first, EH does not fire for server.

If dedicated server was started with -autoInit option, this EH does not fire against server, only for future clients, and all further clients appear to be JIP'ed.

Interesting moment for headless clients, for headless clients instead of [getPlayerUID](../commands/getPlayerUID.md), handler gets string like "HC12160", where '12160' is headless client process ID (matches HC's PID observed in windows task manager)

##### PlayerDisconnected (Arma 3 v1.58 Server Execution)

Executes assigned code when client leaves the mission in MP. Stackable version of [onPlayerDisconnected](../commands/onPlayerDisconnected.md).

```sqf
addMissionEventHandler ["PlayerDisconnected", {
    params ["_id", "_uid", "_name", "_jip", "_owner", "_idstr"];
}];
```

- id: [Number](../topics/Number.md) - unique DirectPlay ID (very large number). It is also the same id used for user placed markers (same as `_id` param)
- uid: [String](../topics/String.md) - [getPlayerUID](../commands/getPlayerUID.md) of the leaving client. The same as Steam ID (same as `_uid` param)
- name: [String](../topics/String.md) - [profileName](../commands/profileName.md) of the leaving client (same as `_name` param)
- jip: [Boolean](../topics/Boolean.md) - [didJIP](../commands/didJIP.md) of the leaving client (same as `_jip` param)
- owner: [Number](../topics/Number.md) - [owner](../commands/owner.md) id of the leaving client (same as `_owner` param)
- idstr: [String](../topics/String.md) - same as id but in string format, so could be exactly compared to [user marker](../commands/allMapMarkers.md) ids

##### PlayerViewChanged (Arma 3 v1.66)

Fired on player view change. Player view changes when player is changing body due to [teamSwitch](../commands/teamSwitch.md), gets in out of a vehicle or operates UAV for example.

```sqf
addMissionEventHandler ["PlayerViewChanged", {
    params [
        "_oldUnit", "_newUnit", "_vehicleIn",
        "_oldCameraOn", "_newCameraOn", "_uav"
    ];
}];
```

- oldUnit: [Object](../topics/Object.md) - player body before EH fired
- newUnit: [Object](../topics/Object.md) - player body after EH fired
- vehicleIn: [Object](../topics/Object.md) - vehicle player is in ([objNull](../commands/objNull.md) if not in vehicle)
- oldCameraOn: [Object](../topics/Object.md) - [cameraOn](../commands/cameraOn.md) before EH fired
- newCameraOn: [Object](../topics/Object.md) - [cameraOn](../commands/cameraOn.md) after EH fired
- uav: [Object](../topics/Object.md) - UAV reference if player is operating one ([objNull](../commands/objNull.md) if not operating UAV)

##### PreloadStarted (Arma 3 v1.58)

Executes assigned code before the mission preload screen. Stackable version of [onPreloadStarted](../commands/onPreloadStarted.md).

> [!IMPORTANT]
> This event handler also fires on client after user closes the main map.

```sqf
addMissionEventHandler ["PreloadStarted", {
    // no params
}];
```

##### PreloadFinished (Arma 3 v1.58)

Executes assigned code after the mission preload screen. Stackable version of [onPreloadFinished](../commands/onPreloadFinished.md).

> [!IMPORTANT]
> This event handler also fires on client after user closes the main map.

```sqf
addMissionEventHandler ["PreloadFinished", {
    // no params
}];
```

##### ProjectileCreated (Arma 3 v2.10)

Triggered when a projectile is created.

```sqf
addMissionEventHandler ["ProjectileCreated", {
    params ["_projectile"];
}];
```

##### SaveGame (Arma 3 v2.18)

Triggered just BEFORE the game saving process started but [isSaving](../commands/isSaving.md) is already set to [true](../commands/true.md). To know when the saving is finished check when [isSaving](../commands/isSaving.md) returns [false](../commands/false.md).

```sqf
addMissionEventHandler ["SaveGame", {
    params ["_saveType"];
}];
```

- saveType: [String](../topics/String.md) - one of "autosaveold", "autosave", "save", "save2", "save3", "save4", "save5", "save6", "continue" or "".

##### ScriptError (Arma 3 v2.14)

Triggered when a script error occurs. See also the `-showScriptErrors` startup parameter.

> [!NOTE]
> Event Handlers have a recursion check. Most of them have a level limit set to **1**;
> **ScriptError** has it set to **2** - meaning that an error occuring inside the Event Handler will trigger once more the EH, but no more than two times total.

```sqf
addMissionEventHandler ["ScriptError", {
    params ["_errorText", "_sourceFile", "_lineNumber", "_errorPos", "_content", "_stackTraceOutput"];
}];
```

- errorText: [String](../topics/String.md) - e.g. "Zero Divisor"
- sourceFile: [String](../topics/String.md) - empty string if spawned [Code](../topics/Code.md)
- lineNumber: [Number](../topics/Number.md) - script's line number
- errorPos: [Number](../topics/Number.md) - script's error byte position in the script *content*
- content: [String](../topics/String.md) - the whole script's [Code](../topics/Code.md) as [String](../topics/String.md)
- stackTraceOutput: [Array](../topics/Array.md) - see [diag_stacktrace](../commands/diag_stacktrace.md) output

##### ScriptSpawned (Arma 3 v2.22)

Executes when any script is spawned.

```sqf
addMissionEventHandler ["ScriptSpawned", {
    params ["_data"];
}];
```

- _data: [Array](../topics/Array.md) with [fileName, content, hash, parentFileName, parentLine, parentScript]
  - fileName: [String](../topics/String.md) - file name of the spawned script, empty when not available
  - content: [String](../topics/String.md) - content of the spawned script
  - hash: [String](../topics/String.md) - hash value of the [Script Handle](../topics/Script_Handle.md)
  - parentFileName [String](../topics/String.md) - file name of the parent script, empty when not available
  - parentLine: [Number](../topics/Number.md) - line number of the parent script
  - parentScript: [String](../topics/String.md) - content of the parent script

##### SelectedActionPerformed

RTM helicopter user action event

```sqf
addMissionEventHandler ["SelectedActionPerformed", {
    params ["_caller", "_target", "_enumNumber", "_actionId"];
}];
```

> [!IMPORTANT]
> Limited or non-existent functionality

##### SelectedActionChanged

RTM helicopter user action event

```sqf
addMissionEventHandler ["SelectedActionChanged", {
    params ["_caller", "_target", "_enumNumber", "_actionId"];
}];
```

> [!IMPORTANT]
> Limited or non-existent functionality

##### SelectedRotorLibActionPerformed

RTM helicopter user action event

```sqf
addMissionEventHandler ["SelectedRotorLibActionPerformed", {
    params ["_caller", "_target", "_enumNumber", "_actionId"];
}];
```

> [!IMPORTANT]
> Works only for key press combination `RightCtrl` + `W`, which is the binding for helicopter wheels brakes. It fires with or without Advanced Flight Model enabled. The enum number returned is 4 and 5, probably because the enum is structured like this:
>
> 0: HelicopterAutoTrimOn
>
> 1: HelicopterAutoTrimOff
>
> 2: HelicopterTrimOn
>
> 3: HelicopterTrimOff
>
> 4: WheelsBrakeOn
>
> 5: WheelsBrakeOff

##### SelectedRotorLibActionChanged

RTM helicopter user action event

```sqf
addMissionEventHandler ["SelectedRotorLibActionChanged", {
    params ["_caller", "_target", "_enumNumber", "_actionId"];
}];
```

> [!IMPORTANT]
> Limited or non-existent functionality

##### Service (Arma 3 v2.12)

Executes assigned code when a serviced vehicle gets rearmed, repaired or refueled. The code executes with interval while the serviced vehicle receives service. If the code returns [true](../commands/true.md) the default on-screen service message is not shown.

```sqf
addMissionEventHandler ["Service", {
    params ["_serviceVehicle", "_servicedVehicle", "_serviceType", "_needsService", "_autoSupply"];
}];
```

- serviceVehicle: [Object](../topics/Object.md) - service vehicle
- servicedVehicle: [Object](../topics/Object.md) - vehicle receiving service
- serviceType: [Number](../topics/Number.md) - 0 - MINOR REPAIR, 1 - REPAIR, 2 - REFUEL, 3 - REARM
- needsService: [Number](../topics/Number.md) - how much serviced vehicle [needsSevice](../commands/needService.md), 0..1 where 0 - no need, 1 - need a lot
- autoSupply: [Boolean](../topics/Boolean.md) - [true](../commands/true.md) if supply started by proximity, [false](../commands/false.md) if supply started due to user action

##### TeamSwitch (Arma 3 v1.58)

Executes assigned code when player teamswitches. Stackable version of [onTeamSwitch](../commands/onTeamSwitch.md).

```sqf
addMissionEventHandler ["TeamSwitch", {
    params ["_previousUnit", "_newUnit"];
}];
```

- previousUnit: [Object](../topics/Object.md) - switching from unit (same as `_from` param)
- newUnit: [Object](../topics/Object.md) - switching to unit (same as `_to` param)

##### UAVCrewCreated (Arma 3 v2.14)

Fires when UAV or UGV is assembled from Backpack after the AI crew is created

```sqf
addMissionEventHandler ["UAVCrewCreated", {
    params ["_uav", "_driver", "_gunner"];
}];
```

- uav: [Object](../topics/Object.md) - the assembled weapon
- driver: [Object](../topics/Object.md) - AI driver
- gunner: [Object](../topics/Object.md) - AI gunner

<sub>Source: [BI Community Wiki — Arma 3: Mission Event Handlers](https://community.bistudio.com/wiki/Arma_3:_Mission_Event_Handlers) (revision 378631).</sub>
