Jump to content
cry me a river

How to count number of times a unit is hit while keeping the unit invincible

Recommended Posts

I am creating a training scenario where the two opposing sides can shoot and hit each other. When an infantry unit is hit twice I want them to go into the surrender animation (place holder for now) and have themselves set to captive so they are not further engaged. However, I do not want anyone to actually die. I've tried using the event handler "hit" but this does not work on anything with set damage false. Is there anyway to count the number of times a unit is hit while also keeping that unit from taking damage?

Share this post


Link to post
Share on other sites
9 minutes ago, cry me a river said:

I am creating a training scenario where the two opposing sides can shoot and hit each other. When an infantry unit is hit twice I want them to go into the surrender animation (place holder for now) and have themselves set to captive so they are not further engaged. However, I do not want anyone to actually die. I've tried using the event handler "hit" but this does not work on anything with set damage false. Is there anyway to count the number of times a unit is hit while also keeping that unit from taking damage?

This was a bit of a headscratcher for me back in the days, since the hit eventhandler ceases to work when a unit is set to allowDamage false.

Might as well rename that command to allowGettingHit..

 

This will do the trick, allowDamage is not needed, the damage upon each hit (even when a bullet hits multiple selections) will be 0 while still allowing the hit eventhandler to work:

test addEventHandler ["Hit",{
	params ["_unit", "_source", "_damage", "_instigator"];

	_hits = _unit getVariable ["TAG_fnc_hits",0];
	_hits = _hits + 1;
	_unit setVariable ["TAG_fnc_hits",_hits];
	hint format ["%1 has been hit %2 times",name _unit,_hits];

	}];
test addEventHandler ["HandleDamage",{0}];

Cheers

  • Like 2

Share this post


Link to post
Share on other sites
On ‎2‎/‎1‎/‎2019 at 1:57 AM, Grumpy Old Man said:

This was a bit of a headscratcher for me back in the days, since the hit eventhandler ceases to work when a unit is set to allowDamage false.

Might as well rename that command to allowGettingHit..

 

This will do the trick, allowDamage is not needed, the damage upon each hit (even when a bullet hits multiple selections) will be 0 while still allowing the hit eventhandler to work:


test addEventHandler ["Hit",{
	params ["_unit", "_source", "_damage", "_instigator"];

	_hits = _unit getVariable ["TAG_fnc_hits",0];
	_hits = _hits + 1;
	_unit setVariable ["TAG_fnc_hits",_hits];
	hint format ["%1 has been hit %2 times",name _unit,_hits];

	}];
test addEventHandler ["HandleDamage",{0}];

Cheers

this works! Im having trouble with the next step which is to cause the unit to be set as captive and undergo the surrender animation when _hits is 2 or greater. Any ideas?

Share this post


Link to post
Share on other sites

actually I got it on my own!

 

Quote

this addEventHandler ["Hit",{
    params ["_this select 0", "_source", "_damage", "_instigator"];

    _hits = _this select 0 getVariable ["TAG_fnc_hits",0];
    _hits = _hits + 1;
    _this select 0 setVariable ["TAG_fnc_hits",_hits];
    hint format ["%1 has been hit %2 times",player,_hits];
    if (_hits > 1) then {_this select 0 setCaptive true; _this select 0 action ["Surrender", _this select 0];};
    }];
this addEventHandler ["HandleDamage",{0}];

 

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×