sizraide 4 Posted July 9 Hello, I have a script that calls when a unit gets damaged, and depending on that damage it incapacitates the unit. My issue is that SIZ_reviveCallOut calls out twice sometimes. This frequently HAPPENS when I shoot the AI on the head once first, then shoot at it's legs a few times until the script sets off and incapacitates the unit, where it will randomly play the SIZ_reviveCallOut function twice. My script, any solution is appreciated: SIZ_enableReviveForUnit = { params["_unit"]; // HandleDamage event handler _unit addEventHandler ["HandleDamage", { params ["_unit", "_selection", "_damage", "_source", "_projectile", "_hitIndex", "_instigator", "_hitPoint"]; if (_damage >= 0.99 && !(_unit getVariable "SIZ_Downed")) then { _unit spawn { [_this, true] call SIZ_setUnitState; waitUntil{sleep 0.5; (lifeState _this == "INCAPACITATED" && _this getVariable "SIZ_Downed")}; _this call SIZ_addReviveAction; _this call SIZ_startBleedout; if(!isPlayer _this && _this getVariable "SIZ_Bleeding") then { sleep 1; if(alive _this) then { _this call SIZ_reviveCallOut; }; // <----- THIS IS THE ERROR }; }; }; _damage; }]; // Killed event handler _unit addEventHandler ["Killed", { params ["_unit"]; [_unit, false] call SIZ_setUnitState; }]; }; Share this post Link to post Share on other sites
Harzach 2424 Posted July 9 The HandleDamage EH can fire multiple times per "hit" due to penetration - see the first sentence in the entry: https://community.bistudio.com/wiki/Arma_3:_Event_Handlers#HandleDamage So your check for SIZ_Bleeding, the sleep, and the function call can initiate multiple times within the space of the first sleep. _projectile should remain the same for each "sub-hit" so you could maybe filter them out that way. That said, the HitPart EH might be a better choice as it registers all "sub-hits" as one event. Share this post Link to post Share on other sites
sizraide 4 Posted July 9 5 hours ago, Harzach said: The HandleDamage EH can fire multiple times per "hit" due to penetration - see the first sentence in the entry: https://community.bistudio.com/wiki/Arma_3:_Event_Handlers#HandleDamage So your check for SIZ_Bleeding, the sleep, and the function call can initiate multiple times within the space of the first sleep. _projectile should remain the same for each "sub-hit" so you could maybe filter them out that way. That said, the HitPart EH might be a better choice as it registers all "sub-hits" as one event. So, I tried using HitPart, but I have one more issue. I am trying to get the accumulated damage of the unit based off hitpoint damage. Somehow, this script doesn't run at all when the accumulated damage reaches beyond 1.5. SIZ_enableReviveForUnit = { params["_unit"]; // HandleDamage event handler _unit addEventHandler ["HitPart", { (_this select 0) params ["_target", "_shooter", "_projectile", "_position", "_velocity", "_selection", "_ammo", "_vector", "_radius", "_surfaceType", "_isDirect"]; _totalDmg = 0; { _totalDmg = _totalDmg + _x } forEach (getAllHitPointsDamage _target select 2); hint str _totalDmg; // DEBUG, it works. if(_totalDmg >= 1.5) then { // Doesn't fire when _totalDmg goes beyond 1.5? if !(_unit getVariable "SIZ_Downed") then { _unit spawn { [_this, true] call SIZ_setUnitState; waitUntil{sleep 0.5; (lifeState _this == "INCAPACITATED" && _this getVariable "SIZ_Downed")}; _this call SIZ_addReviveAction; _this call SIZ_startBleedout; if(!isPlayer _this && _this getVariable "SIZ_Bleeding") then { sleep 1; if(alive _this) then { _this call SIZ_reviveCallOut; }; }; }; }; }; }]; // Killed event handler _unit addEventHandler ["Killed", { params ["_unit"]; [_unit, false] call SIZ_setUnitState; }]; }; Share this post Link to post Share on other sites