Jump to content
domcho

Check for any unit in group matching a condition

Recommended Posts

How do you check a group to see if any of the group members match a condition in general? For example, how would you make the game display a hint that a soldier from a group has been injured, but do it only once until that soldier is healed and wait until he is damaged again to display the hint? I tried this:

{if (damage _x >= 0.1) then {

hint ("Soldier " + name _x + " is injured!");};} forEach units myGroup;

However there are multiple problems with this - the code loops through the whole group every time and only displays the highest indexed soldier of the group in the hint. It doesn't disregard already injured soldiers that were displayed on the hint. Another problem is that this can't be used in a trigger, unless, I assume, it is put in an endless loop and the trigger is fired once at the beginning of the game. I was looking for a way to do it with using a condition in the trigger's condition field and then using the activation box, but I guess it's not possible?

Other than that how would you do a one time check for any unit in a group matching a condition?

Share this post


Link to post
Share on other sites

You could use the event handlers:

https://community.bistudio.com/wiki/Arma_3:_Event_Handlers#HandleDamage

https://community.bistudio.com/wiki/Arma_3:_Event_Handlers#HandleHeal


 

{
  _x addEventHandler ["HandleDamage", {
    params ["_unit", "_selection", "_damage", "_source", "_projectile", "_hitIndex", "_instigator", "_hitPoint"];
    hint format ["%1 has been injured",name _unit];
  }];

  _x addEventHandler ["HandleHeal", {
    params ["_injured", "_healer"];
    hint format ["%1 has been healed by %2",name _injured,name _healer];
  }];
} forEach units myGroup;

 

 

  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites
Spoiler
21 hours ago, pierremgi said:

You could use the event handlers:

https://community.bistudio.com/wiki/Arma_3:_Event_Handlers#HandleDamage

https://community.bistudio.com/wiki/Arma_3:_Event_Handlers#HandleHeal


 



{
  _x addEventHandler ["HandleDamage", {
    params ["_unit", "_selection", "_damage", "_source", "_projectile", "_hitIndex", "_instigator", "_hitPoint"];
    hint format ["%1 has been injured",name _unit];
  }];

  _x addEventHandler ["HandleHeal", {
    params ["_injured", "_healer"];
    hint format ["%1 has been healed by %2",name _injured,name _healer];
  }];
} forEach units myGroup;

 

 

 

Would event handler "Hit" be a valid substitute for "HandleDamage" here? I remember using Hit back in Operation Flashpoint. But reading the wiki page you linked, it seems HandleDamage has more parameters and thus opens up more possibilities? Anyway, this is perfect, thanks a lot!

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

×