Home   Help Search Login Register  

Author Topic: Event handler script  (Read 1947 times)

0 Members and 1 Guest are viewing this topic.

Offline Ext3rmin4tor

  • Members
  • *
Event handler script
« 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.
« Last Edit: 13 Aug 2011, 17:23:41 by Ext3rmin4tor »
How can you shoot women and children?
Easy! Ya' just don't lead'em so much! Ain't war hell?!!

Offline Wolfrug

  • Addons Depot
  • Former Staff
  • ****
  • Official OFPEC Old Timer
Re: Event handler script
« Reply #1 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.
"When 900 years YOU reach, look as good you will not!"

Offline Ext3rmin4tor

  • Members
  • *
Re: Event handler script
« Reply #2 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.
How can you shoot women and children?
Easy! Ya' just don't lead'em so much! Ain't war hell?!!