OFPEC Forum

Editors Depot - Mission Editing and Scripting => Arma2 - Editing/Scripting General => Topic started by: Ext3rmin4tor on 13 Aug 2011, 17:04:30

Title: Event handler script
Post by: Ext3rmin4tor on 13 Aug 2011, 17:04:30
I added an event handler (type "Killed") for civilian units which calls a script. The problem is that the script is executed twice, and I don't understand why because the "Killed" event handler should trigger only when the unit dies, and that happens only once. Do you have any clues?

EDIT:
I found the problem: civilian units have also a "Hit" event handler, and it looks like that if the unit dies, the "Hit" event handler fires anyway, although the biki says it does not.
Title: Re: Event handler script
Post by: Wolfrug on 13 Aug 2011, 20:50:40
You could also use "handledamage" which should handle both "killed" and "hit". As long as you remember to output _damage from the script you run, it shouldn't interfere with regular damage handling. E.g.:

civ1 addeventhandler ["handledamage", {_this call compile preprocessfilelinenumbers "script.sqf"}];

Code: [Select]
// script.sqf

_unit = _this select 0;
_damage = _this select 2;

Hint format ["%1 was hit for %2 damage!", _unit, _damage];

_damage

(yes, no ; after damage). At least in theory :)

Wolfrug out.
Title: Re: Event handler script
Post by: Ext3rmin4tor on 13 Aug 2011, 21:38:08
I solved using just the "Hit" handler and considering the case the civilian is either dead or injured in the script with the alive function.