Jump to content
Sign in to follow this  
Evilhardt

check if has been KILLED (not !alive)

Recommended Posts

So I have a group of units all of which have a probability of presence. I want a trigger to fire if one of those units has been killed. I I use "!alive unit_1 OR !alive unit_2 OR... ...!alive unit_n" the trigger wo#'t work if one of those units has not even spawned to begin with because of probability of presence... How can I check if a unit actually has ben KILLED rather than is not alive?

Share this post


Link to post
Share on other sites

Make sure the object (unit) is not null before checking if its alive.

{   !(isNull _x) && { !(alive _x) }  }count [unit1, unit2, unit3, unit4] == 0

The {} wrapped around !(alive _x) make sure it is only checked if !(isNull _x) is true.

So if it exists, see if its alive.

Share this post


Link to post
Share on other sites

after the "group" was created, add an event killed for each unit of the "group" .

{

_x addeventhandler ["killed", {job to do;}];

}foreach units "group";

Share this post


Link to post
Share on other sites

Thanks.

@ mariodu62: In my case it is not a group of units. They're all single units, since I have placed them at specific locatiosn and when they are grouped they will immediately leave those positions to regroup with their leader.

@ Larrow: I see. I tried to implement your script like this:

{   
!(isNull _x) && { (!alive _x) AND (alive flareGuy) }  
}
count [s1, S2, S3, S4, S5, S6, S7] == 0; 

So, I have units S1 through S7 and the unit flareGuy. I want the flareGuy to launch a flare if one member of the set {S1, S2, S3, S4, S5, S6, S7} has been killed and he himslef is still alive. So, I ave put that into the condition field of the trigger that also launches the flare. But nothing happens once I replace the old condition with the one above and one member of the set is killed. Only once I also kill flareGuy the trigger fires... ?? But it explicitly say !alive _x AND alive flareGuy. What am I doing wrong? :/

Edited by Evilhardt

Share this post


Link to post
Share on other sites

My code was not a direct fix to your problem but an example of how you can check if a unit exists, so checking anything else (e.g alive) does not throw an error.

If you want to know that at least 1 unit is dead but not care about who then something like...

{ !(isNull _x) && { !(alive _x) }  }count [s1,s2,s3,s4,s5,s6,s7] > 0 && alive flareguy 

Out of those that exist, if atleast 1 is dead AND the flareGuy is alive then return TRUE

Should do the job

OR

You can use Mariodu62 example, it does not matter that they are not in a group to begin with just add a killed event to each one that runs your code.

Share this post


Link to post
Share on other sites

if it's an array, replace group by the array...

{

_x addeventhandler ["killed", {job to do;}];

}foreach [s1,s2,s3,s4,s5,s6,s7];

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
Sign in to follow this  

×