Arma 3 Scripting

addEventHandler

  • Global argument
  • Local effect
  • Arma 3 v0.50
  • First in Operation Flashpoint v1.85

Command · Markdown · JSON · original wiki page

Description

Adds an Event Handler to the given object.

Syntax

target addEventHandler [type, code]

Parameters:

Returns: Number - the index of the added Event Handler. Indices start at 0 for each unit and increment with each added Event Handler.

Examples

Example 1

this addEventHandler ["Killed", {
    params ["_unit", "_killer"];
    systemChat format ["%1 has been killed by %2.", _unit, _killer];
}];

Example 2

_index = player addEventHandler ["Killed", { _this exec "playerKilled.sqs" }]

Multiplayer

Some event handlers are persistent (i.e they stay attached to the unit, even after it dies and respawns).

See also

removeEventHandler · removeAllEventHandlers · addMPEventHandler · addMissionEventHandler · BIS_fnc_addScriptedEventHandler · getEventHandlerInfo

Community notes

Killzone_Kid

When using overridable EH, such as "InventoryOpened" and similar, where returning true allows to override default action, exitWith cannot be used to return value. So:

if (whatever) exitWith {true}; false;

Forget about it, will not work. Instead use:

if (whatever) then {true} else {false};

100% satisfaction guaranteed!