Check if all unit 'west' is dead, if so do x

Recommended Posts

Hello, so i am trying to figure out the code behind checking whether or not an entire unit is dead

Here is the code i tried but didn't have no success

```players = allPlayers;

{
if(side _x == west) then
{
}

can anyone help me?

Share on other sites
```_westPlayers = allPlayers select {side _x == west};//Returns all players of side west.

_aliveDeadPlayers = _westPlayers count {alive _x};//Returns how many west players are alive. Will be 0 if all are dead.```

Share on other sites
5 hours ago, Dedmen said:
```
_westPlayers = allPlayers select {side _x == west};//Returns all players of side west.

_aliveDeadPlayers = _westPlayers count {alive _x};//Returns how many west players are alive. Will be 0 if all are dead.```

Maybe an oversight, the correct syntax would be:

`_aliveDeadPlayers = {alive _x} count _westPlayers;`

Cheers

• 1

Share on other sites

?

```_westCount = allPlayers select {side _x == west && alive _x};
if (count _westCount == 0) then
{
};```

Share on other sites
10 hours ago, Dedmen said:

_westPlayers = allPlayers select {side _x == west};//Returns all players of side west.

_aliveDeadPlayers = _westPlayers count {alive _x};//Returns how many west players are alive. Will be 0 if all are dead.

These will both be the same, as a dead players side is CIV no matter their original side.

```if ( count( allPlayers select{side _x == west} ) == 0 ) then {
};```

Share on other sites
44 minutes ago, Larrow said:

These will both be the same, as a dead players side is CIV no matter their original side.

```
if ( count( allPlayers select{side _x == west} ) == 0 ) then {
};```

i thought that was just AI that turned to civ upon death?

Share on other sites
On 5/30/2018 at 7:50 PM, gokitty1199 said:

i thought that was just AI that turned to civ upon death?

No, player units do as well. Test it out in a quick 2 player hosted from the editor, with...

`allPlayers apply{ side _x }`

In a watch line in the debug console. As soon as you shoot the other player you will see CIV in the list. Once he respawns it will be back to WEST.

You could just do...

```if ( west countSide allPlayers isEqualTo 0 ) then {
hint "All west players are dead";
};```

• 2