Jump to content
Sign in to follow this  
Guest Ti0n3r

How to check if a group is "alive"

Recommended Posts

Guest Ti0n3r

Sorry for this rather dumb question, but how do I check if a group (or more than one group) is alive? I used this a lot in OFP but either I forgot how to do it, or the command for doing this has been changed in ArmA.

Any help would be very appreciated smile_o.gif

PS: I tried browsing the pinned threads in ArmA editing & OFP editing & also the wiki

Share this post


Link to post
Share on other sites

An example function I made for OFP:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">private "_grpAlive";

_grpAlive = false;

if ( {alive _x} count units _this > 0 ) then { _grpAlive = true; };

_grpAlive

It takes the group as an argument. Returns true if group has at least 1 alive member, false if all are dead

I think it should work in ArmA too but I haven't tried it in ArmA.

Edit: oh yes, forgot to say that in these cases it could be worthwhile to check the functions available at the Editors Depot of http://www.ofpec.com/ as this example is listed there and many others.

Share this post


Link to post
Share on other sites
Guest Ti0n3r

Thanks, but I'm 99% sure there used to be a way to simply but something very basic into the condition field of a trigger to check if a group was alive/dead, like;

"not alive nameofgroup"

Damn I've been trying to find out how to do it for 2 hours rofl.gif

Share this post


Link to post
Share on other sites

Baddos suggestion works.

Cond: (count (units someGroup)) == 0

OnAct: player sideChat "OMG, group is dead!";

Should work too.

Share this post


Link to post
Share on other sites
Guest Ti0n3r
Quote[/b] ]Cond: (count (units someGroup)) == 0

I was blind notworthy.gif

Share this post


Link to post
Share on other sites

Wouldnt you have to count the alive units in the group, i thought it still classed kia units as part of the group when it counted???

Cheers

GC

Share this post


Link to post
Share on other sites
Wouldnt you have to count the alive units in the group, i thought it still classed kia units as part of the group when it counted???

Cheers

GC

Using <span style='color:blue'>({alive _x} count units _group == 0)</span> could be better, but that depends on the intended purpose.

The game removes units from a group when it finds out they are dead, and that takes some time.

When there is at least one alive unit in the group, it's relatively fast, because the unit's AI routines helps to find whether other units in their groups are dead.

...not long ago, someone was asking somewhere about deleting groups - if, for example, you would want to execute deleteGroup command when this condition is true, then it could not work because only empty groups can be deleted and the game may have not yet removed the dead unit from the group.

Share this post


Link to post
Share on other sites

Back in OFP RES I made a killed EH and tried to get the group of the killed unit. It allways seemed to return grpnull which didnt work for me. I could see the correct group name at first with a hint. But once the switch occured my script would break, as if I was understanding local variables as pointers wrong and my group name would just vanish.

In that EH I wound up putting a reference number for each group and unit so I could get that info.

At that point in my script the group could subtract from a seperate group count variable (not the internal count command) and then be checked for its count both for zero (Dead).

Incidentally, a percentage can also be set to give the group more realistic behaviour. Like a retreat and reinforce feature if the group is below certain % threshold.

Share this post


Link to post
Share on other sites
Back in OFP RES I made a killed EH and tried to get the group of the killed unit. It allways seemed to return grpnull which didnt work for me.

No problem in ArmA - it takes about 10 seconds before the game "get to know" that the unit has been killed and then the unit is removed from the group.

So you have about 10 seconds to run the <span style='color:blue'>(_grp = group _killedUnit)</span> before the unit is automaticaly removed from the group (then the command would return null, or maybe even result in an error? - i didn't tried, but it certainly wouldn't work)

edit: the 10 seconds timeout isn't reliable, it's just my guess - in reality it can be 1 second, or 5, or maybe even 15 - all depends on many factors, but one thing is certain: you have plenty of time when using the code in "killed" EH.

Share this post


Link to post
Share on other sites
Thanks, but I'm 99% sure there used to be a way to simply but something very basic into the condition field of a trigger to check if a group was alive/dead, like;

"not alive nameofgroup"

Damn I've been trying to find out how to do it for 2 hours rofl.gif

Well if you look at the function aliveGroup, it actually helps you do exactly that.

Quote[/b] ]// USAGE:

// init: aliveGroup = preprocessFile "aliveGroup.sqf"

// calling: <group> call aliveGroup

// returns: <boolean>

Example (I promise it works in OFP as I haven't used this in ArmA):

Into a trigger's condition field:

(group player) call aliveGroup

That would then give you either true or false. If this has to be done by scripting then I don't know how much more simple it can get. I wrote the function as it is easier to remember how to call it than to think how the syntax went for the function itself.

Maybe there is some shorter way to do it in ArmA's triggers (without writing any code) but I didn't look into it yet and can't do it now either.

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  

×