Jump to content
TheGoldenStar

Unit's God mode toggle off doesn't work in a trigger

Recommended Posts

i've been trying to make a small WW2 Mission which seemed fun. I wanted 2 fireteams to suppres the enemies while unloading from their boats, and that works just as fine, i needed to set  aswell god mode to the unit cus otherwise enemies will just headshot the shit out of them, so i had this code embedded into the object init of the unit 1 and 2:

this addEventHandler ["HandleDamage", {false}];

but then, i didn't want them to be alive for ever so what i did was, place a trigger and whenever a BLUFOR would enter the trigger area, the trigger will activate, the activation code is this one
 

fireteam1 addEventHandler ["HandleDamage", {true}];
fireteam2 addEventHandler ["HandleDamage", {true}];
//since fireteam1 and fireteam2 are the names of the units

Tho it just gives me "Generic Error in Expression" i don't really know what am i missing in here, I really need your help. I am aswell posting some screenshots down here so you can get a better understanding of what i am having in my editor. Thanks in advance to everyone!

Spoiler

i2ReKJk.png

 

eVCU3xR.png

 

s4GWvpc.png

 

GI0SGFG.png

 

Share this post


Link to post
Share on other sites

fireteam1 and fireteam2 aren't "units," they are "groups" and must be handled as such:

{_x addEventHandler ["HandleDamage", {true}]} forEach fireteam1;
{_x addEventHandler ["HandleDamage", {true}]} forEach fireteam2;

or

{
  _y = _x;
  {
    _x addEventHandler ["HandleDamage", {true}]
  } forEach units _y;
} forEach [fireteam1, fireteam2];

or

_ftUnits = units fireteam1 + units fireteam2;
{
  _x addEventHandler ["HandleDamage", {true}]
} forEach _ftUnits;

...etc.

  • Like 4

Share this post


Link to post
Share on other sites

Don't double handleDamage EH for nuts.  Basically the event is the same. You just overwrite your previous code by another one. The last code wins but it's not a good habit.  Keep on mind the syntax and parameters also.

And no, fireTeam1 (2) here is not a unit but a group

Name your trigger (trgBeaching or else)


 

{
  _x addEventHandler ["handleDamage", {
    params ["_unit", "", "_damage"];
    if (triggerActivated trgBeaching) then {
      _unit removeEventHandler ["handleDamage",_thisEventHandler ];
      _damage
    } else {0}
  }]
} forEach (units fireTeam1 + units fireTeam2);

 

NOTE: The units will start to die under fire when the trigger is activated, no matter their positions. If you want they stay alive until entering the trigger (individually), just replace the condition:

triggerActivated trgBeaching

by

_unit inArea trgBeaching

That's all.

 

  • Like 4

Share this post


Link to post
Share on other sites

Thanks to everyone for the answers i'll get along testing as soon as i can ❤️

 

EDIT: @Harzach @pierremgi You guys are the best everything is now working, Thanks for the help :))

 

{
  _x addEventHandler ["handleDamage", {
    params ["_unit", "", "_damage"];
    if (triggerActivated trgBeaching) then {
      _unit removeEventHandler ["handleDamage",_thisEventHandler ];
      _damage
    } else {0}
  }]
} forEach (units fireTeam1 + units fireTeam2);
  • Like 2

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

×