Home   Help Search Login Register  

Author Topic: addEventHandler runs two times?  (Read 435 times)

0 Members and 1 Guest are viewing this topic.

exodus400

  • Guest
addEventHandler runs two times?
« on: 16 Sep 2004, 20:16:44 »
I am trying to use addEventHandler for the first time, but at each activiation it executes two times.

In init.sqs I have:

firstsq = units group a1sq1
"_x addEventHandler [{dammaged}, {_this exec {hit.sqs}}]" forEach firstsq

in hit.sqs I have:

_hit = _this select 0
hitlist = hitlist + [_hit]
doc sidechat format["Hitlist %1",hitlist]

When someone gets hit it runs hit.sqs once and everything is fine but then it repeats one more time and makes the sidechat and adds _hit one more time. Why?

Thanks for help!

Offline General Barron

  • Former Staff
  • ****
  • Semper Fi!
Re:addEventHandler runs two times?
« Reply #1 on: 17 Sep 2004, 07:17:57 »
The 'dammaged' EH is a little... wacky. What you should be using is the "hit" EH, which executes once each time a unit is hit (for enough damage).

From messing around with the 'dammaged' EH, I've noticed it works in the following way. When a part of a unit's body is damaged enough (usually when it turns 'bloody', like when the arms or legs turn 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. Eg, 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.

Unfortunately the above facts make the 'dammaged' EH much less useful than it could be, in my opinion.
« Last Edit: 17 Sep 2004, 07:18:10 by General Barron »
HANDSIGNALS COMMAND SYSTEM-- A realistic squad-control modification for OFP
kexp.org-- The best radio station in the world, right here at home! Listen to John Richards!

exodus400

  • Guest
Re:addEventHandler runs two times?
« Reply #2 on: 17 Sep 2004, 14:14:08 »
Hmm, have to rewrite my whole medic script I guess.... damn!

Anyway, I moved the addEventHandler from init.sqs to another script and it stopped executing twice, maybe EventHandlers doesn't work to good with init.sqs?

Thanks for the info!