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

Scripting can be used to add an event handler to specific object in-game. However, for custom created content, you can add event handlers to all objects of a given type by placing them in the object's config. Example:

class CfgVehicles
{
     //...
     //(other config code)
     //...

     class myVehicle: car
     {
          //...
          //(other config code)
          //...

          class EventHandlers
          {
               init = "_this execVM 'myscript.sqf'";
               fired = "_this execVM 'otherscript.sqf'";
          };
     };
};

More information on config EH available in the VBS Developer Reference.

Note: Event handlers added in the config can not be removed using the removeEventHandler command.

Most event handlers listed here are placed in the object's config (CfgVehicles). However, a few events should be placed in CfgWeapons (see Fired) or CfgAmmo (see AmmoExplode.2C AmmoHit). Example:

class CfgWeapons
{
     //...

     class myRifle: vbs2_rifle
     {
          //...

          class EventHandlers
          {
               fired = "_this execVM 'firedscript.sqf'";
          };
     };
};

class CfgAmmo
{
     //...

     class myRocket: vbs2_rocket
     {
          //...

          class EventHandlers
          {
               ammoExplode = "_this execVM 'explodescript.sqf'";
          };
     };
};

Collision Event Handlers

Special event handlers for collisions can be added either via the command addCollisionEventHandler or in a vehicle's config file:

class CollisionEventHandlers
{
   class MainRotor
   {
      repeat=false;
      component="MainRotor";
      event="hint format ["Main Rotor Hit:"%1"",_this]";
   };
   class TailRotor
   {
      repeat=false;
      component="TailRotor"
      event="hint format ["Tail Rotor Hit:"%1"",_this]";
   };
};