Dramacius 8 Posted July 10, 2023 Hi all, is there an event handler or way of outputting the number of popup targets that are down? I am running a shooting range that has a timer which stops when all the targets are down, I've been using the EH `hit` to detect if a target has been hit but there are occassions when the target can be hit multiple times before its fully down and it returns false hits in my counter stopping the counter before all targets are down. for reference this is the code for my targets DDR5_RangeTargets = this nearObjects ["TargetP_Inf_F", 40]; targetsHit = 0; { _x setVariable ["nopop", true]; _x addEventHandler ["hit", {targetsHit = targetsHit + 1}]; } forEach DDR5_RangeTargets; Share this post Link to post Share on other sites
krzychuzokecia 717 Posted July 10, 2023 Methinks you need to remove the "hit" EH after doing the "targetsHit = targetsHit +1" part. If you don't remove the "hit" EH on an already hit target, then it will still be active, and fire every time the target is hit (seems obvious, but apparently it isn't so). So something along the lines of: { _x setVariable ["nopop", true]; _x addEventHandler ["hit", {targetsHit = targetsHit + 1, _x removeAllEventHandlers "hit"}]; } forEach DDR5_RangeTargets; (I'm not really sure of the syntax, it's been ages since I coded anything for Arma) Also, you might have not noticed it yet, but with "hit" EH it's possible to hit the pop-up target stand (instead of target proper) and game will still think it's all fine. Well, it is hit afterall, but since you wanna test player's marksmanship, you want to make sure that player is hitting proper part of the model. For that you can use "HitPart" EH. Example code from my old mission (be warned, I had no idea what I was doing here, so it's prolly a bad script, but it works): { _x setDamage 0; _x animate ["terc", 0]; _x addEventHandler ["HitPart",{_targ=((_this select 0) select 0), _sel=((_this select 0) select 5), _ammo=((_this select 0) select 6), if ((_sel find "target" >=0) AND (_ammo find "B_65x39_Caseless" >=0)) then {points = points + 1, RangeOff sideChat "Hit!", _targ RemoveAllEventHandlers "HitPart"}}]; } forEach [d_r_1,d_r_2,d_r_3,d_r_4]; As you can see, with HitPart you need to know what's the name of the selection you want to activate the script. For pop-up targets it's just "target", so what I did here was first to get the name of hit selection ("_sel=((_this select 0) select 5)"), and then check if it's name is "target" ("(_sel find "target" >=0)"). 1 Share this post Link to post Share on other sites
Dramacius 8 Posted July 10, 2023 1 hour ago, krzychuzokecia said: Methinks you need to remove the "hit" EH after doing the "targetsHit = targetsHit +1" part. If you don't remove the "hit" EH on an already hit target, then it will still be active, and fire every time the target is hit (seems obvious, but apparently it isn't so). So something along the lines of: { _x setVariable ["nopop", true]; _x addEventHandler ["hit", {targetsHit = targetsHit + 1, _x removeAllEventHandlers "hit"}]; } forEach DDR5_RangeTargets; (I'm not really sure of the syntax, it's been ages since I coded anything for Arma) Thanks I have managed to implement something like this (not on the computer right now to get the exact code I used but it sort of works as long as I am not using full auto as that seems to register multiple hits before it removes the event handler. Share this post Link to post Share on other sites
Larrow 2820 Posted July 10, 2023 Use DDR5_RangeTargets to keep track of what still needs to be hit? DDR5_RangeTargets = this nearObjects[ "TargetP_Inf_F", 40 ]; targetsHit = 0; { _x setVariable[ "nopop", true ]; _x addEventHandler[ "hit", { params[ "_target" ]; if ( _target in DDR5_RangeTargets ) then { DDR5_RangeTargets = DDR5_RangeTargets - [ _target ]; targetsHit = targetsHit + 1; _target removeEventHandler[ _thisEvent, _thisEventHandler ]; }; }]; } forEach DDR5_RangeTargets; 1 Share this post Link to post Share on other sites