Page tree
Skip to end of metadata
Go to start of metadata

Introduced in



Description:Adds an event handler to a given unit, group, or munition.

For a list of available event handlers, see Category VBS Event Handlers. You may add as many event handlers of any type as you like to a given unit.

Note: If you add an event handler of a given type, when one already exists, the old event handler does not get overwritten. Use removeEventHandler to delete event handlers.

Every event creates an array named _this, which contains specific information about the particular event (for example, the "killed" event handler returns an array with 2 elements: the killed unit, and the killer).

See VBS Custom Event Handlers for additional events, not added to a specific entity.


Syntax:target addEventHandler [type, code, parameters]
  • target: Object, Group, or Side - Data Type - Indicates what receives the event handler (most events are added to an Object, except when noted otherwise).
  • type: String - Event handler type (see Category VBS Event Handlers for options).
  • code: String or Code - Code to execute, once the event occurs. The code receives the event data in the _this variable, depending on the event type.
  • parameters: Array -  List of parameters to pass to the event handler. The parameters are specific to the type of event handler added, and need to be specified by name as a string, followed by the value. For example, ["PARAM1", value1, "PARAM2", value2...]. Each available parameter is optional, and if not specified, has a default value (optional) (V18.3+).
Return Value:Number - Event handler index.


(group player) addEventHandler ["WaypointComplete",{hint "waypoint complete"}]
(vehicle player) addEventHandler ["IncomingProjectile",{hint "projectile detected at 25m"}, ["TRIGGER_DISTANCE", 25]]

Additional Information

See also: removeEventHandler, fn vbs addSysEventHandler, addMPEventHandler, Category VBS Event Handlers


Currently, the only available event handler that can be added to groups (instead of objects) is
. --
General Barron
02:38, 18 February 2009 (CET)

The function which the Event Handler calls cannot contain sleep statements. To utilize a sleep statement, spawn a second function to run in its own thread. -- Richard Kissel