You are on page 1of 2

Event Handlers

by Igor

Drukov

(edited by bedges)

Recommended for OFP version 1.90 (OFP: Resistance) Basically, you could sum up the plot as follows : unit_name AddEventHandler ["Event",{consequences}] Usually, you add this in the init field of the given unit, but you can do so in the activation fields of triggers, or in scripts. The "Events" are limited, but the consequences can be just about anything. The power of this command lies in the values returned. Each EH returns specific values, which are priceless. Here are the returned values of the most famous EH, "fired", which can be added to either vehicles or men : _this select 0 : _this select 1 : _this select 2 : _this select 3 : _this select 4 : who fired with what weapon with what muzzle mode (either single, or burst, or auto) the type of ammo used

So if you create a 'fired' eventhandler like this joe AddEventHandler ["fired",{_this exec "onfiring.sqs"}] you can start your "onfiring.sqs" script with _man = _this select 0 _ammo = _this select 4 The remaining EHs and their returned values are as follows: "killed" (addable to men or vehicles) : _this select 0 : who's dead _this select 1 : whodunnit (say, the killer) "getin" and "getout" (to vehicles only) : _this select 0 : the vehicle the EH is attached to _this select 1 : in/from what position (driver, gunner, commander, cargo) _this select 2 : who's just got in/out "hit" (men or vehicles) : _this select 0 : who's hit (can be either a man or a vehicle) _this select 1 : who did the shooting _this select 2 : scalar damage value "incomingmissile" (only works with units that can be "locked" by a missile) : _this select 0 : target unit _this select 1 : type of missile _this select 2 : shooter

"dammaged" (doesn't work for vehicles) : _this select 0 : who's damaged _this select 1 : what part of the body has been hit ("nohy" for the legs, "ruce" for the hands, "hlava" for the head, "telo" for the torso) _this select 2 : scalar damage value This EH does NOT return who fired the shot. When a part of a unit's body is damaged enough - usually when it turns 'bloody' then the EH executes. If more than one part of the body is damaged in one hit (like from a grenade blast, which hits all body parts, or a bullet to the chest, which usually hits the chest and the arms), then the EH will execute once for each body part damaged. Now, once a certain body part has been 'dammaged' and executes the EH, the EH will not execute again for that body part, i.e. if a unit's legs are hit and the EH executes for the legs, shooting the unit in the legs again will not execute the EH again, no matter how much damage is done. Only by using the 'setdammage' command (unit setdammage 0) on the unit can the EH fire again for that body part. "gear" (this EH refers to the gear of a plane and will only activate if pilot lowers or lifts landing gear, and if added to a PLANE) : _this select 0 : who the driver is _this select 1 : boolean value, true if gear is down, false otherwise "engine" (to vehicles only) : _this select 0 : who's in charge of the vehicle _this select 1 : boolean, true if engine is on, false otherwise "fuel" (this EH will activate only for significant changes of the fuel level) : _this select 0 : vehicle _this select 1 : boolean, true if there's fuel, false otherwise Note: EHs are not compatible with multiplayer games. The "init" eventHandler only seems to work from a unit's config (this is addon editing territory). The init event occurs only where the unit is local when the unit is created. In the case of soldiers, the init event also occurs when the soldier exits a vehicle. Init's select 0 is the unit, I haven't tried any of the other params. An annoying thing about "init" EH's (used in an addon's config), is that they are also fired whenever the unit exits a vehicle. To prevent serious bugs from this, you should do the following: Execute a script from the EH. In the script, check to see if the unit is in a global array you create. If it ISN'T in the array, add it to the array, and continue with the script. If it IS in the array, exit the script. You can use the format command to pass some additional info to an EH added via script, visit the following link http://www.ofpec.com/index.php?option=com_smf&Itemid=36&topic=17724.0

You might also like