# [SOLVED]Percentage of killed enemies inside a trigger

## Recommended Posts

Hi folks,

I'm trying to create a trigger that activates when 50% of the enemies are killed.

I'm using this, but doesn't seems to work properly:

```({alive _x && side _x == east} count thisList) <= ((({alive _x && side _x == east} count thisList))*0.5);
```

What is wrong with this?

Thanks!

##### Share on other sites

Two brackets are totally same!

So, solution:

`({not alive _x && side _x == east} count thisList) <= ((({alive _x && side _x == east} count thisList))*0.5);`

##### Share on other sites

Hi folks,

I'm trying to create a trigger that activates when 50% of the enemies are killed.

I'm using this, but doesn't seems to work properly:

```({alive _x && side _x == east} count thisList) ) <= ((({alive _x && side _x == east} count thisList))*0.5);
```

What is wrong with this?

Thanks!

if that is ur triggers condition then its nearly the same as if u would say

(1 <= 0.5)

can that condition be fullfilled? No.

What u ve to know is how much enemies were in triggers area at start of the battle and then u could do something like this:

```{alive _x && side _x == east} count thisList < 0.5 * initial_enemy_count
```

##### Share on other sites

Two brackets are totally same!

So, solution:

`({not alive _x && side _x == east} count thisList) <= ((({alive _x && side _x == east} count thisList))*0.5);`
thats not the solution. it is true if 10 enemies r dead and 100 are alive

10 <= 50 is true

just to say this could be the solution:

```count (thisList select{not alive _x && side _x == east}) >= count (thisList select {side _x == east}) * 0.5
```
but u ve a problem if u ve a running cleaning script which deletes dead bodies. thats the reason why i would count enemies at start of battle.
• 1

##### Share on other sites

if that is ur triggers condition then its nearly the same as if u would say

(1 <= 0.5)

can that condition be fullfilled? No.

What u ve to know is how much enemies were in triggers area at start of the battle and then u could do something like this:

```{alive _x && side _x == east} count thisList < 0.5 * initial_enemy_count
```

That makes sense, I didn't think the way triggers keep checking condition.

Also, I don't want to count all enemies every time I create a trigger like this, even to keep the mission funny to me.

I thought on creating a little code that stores the initial enemy count inside some trigger and then, the same trigger uses this value to compare with the actual condition, but I don't know if that is possible.

##### Share on other sites

do u have a running clean script which deletes dead bodies? if not use the solution of my last post. if u use such clean script just say and someone will think about :-)

##### Share on other sites

thats not the solution. it is true if 10 enemies r dead and 100 are alive

10 <= 50 is true

just to say this could be the solution:

```count (thisList select{not alive _x && side _x == east}) >= count (thisList select {side _x == east}) * 0.5
```
but u ve a problem if u ve a running cleaning script which deletes dead bodies. thats the reason why i would count enemies at start of battle.

Tested and didn't work either, the condition is met only when I kill everyone.

About the cleaning script, I think I can disable it without any further issues if the purpose is to make this work.

EDIT: A very innocent code idea that I had before

1)Code:

count_mytrigger = count (thisList select{not alive _x && side _x == east}) <- Stores the initial enemy count

2)Trigger

({not alive _x && side _x == east} count thisList) >= count_mytrigger

Edited by luks7n

##### Share on other sites

yeah correct.

I tested it and now i think I know why.... deads r changing side to civilian...

if u ve no other civilian there, use this:

```count (thisList select{side _x == civilian}) >= count (thisList select {side _x == east}) * 0.5
```
hmm ... not working. :unsure:

this is tested and working:

```count (thisList select{side _x == civilian}) >= count (thisList select {side _x == east})
```
but as I said u should not have a clean up script working and there shouldnt be civilians in the trigger area!

lol thats not working ... all dead bluefor will be counted as well... its harder to solve as thought at first.

that leads me to a post of grumpy. it could be done with looking at configfile for the side...

Edited by sarogahtyp
• 1

##### Share on other sites

yeah correct.

I tested it and now i think I know why.... deads r changing side to civilian...

if u ve no other civilian there, use this:

```count (thisList select{side _x == civilian}) >= count (thisList select {side _x == east}) * 0.5
```
hmm ... not working. :unsure:

this is tested and working:

```count (thisList select{side _x == civilian}) >= count (thisList select {side _x == east})
```
but as I said u should not have a clean up script working and there shouldnt be civilians in the trigger area!

What is the problem with * 0.5 then?

Would be nice to be able to use this with another percentage, like 90% of dead enemies.

I must count them, unfortunately  :(

Edited by luks7n

##### Share on other sites

if 50 % r dead then the numer of deads is equal with the number of the alives. therfore no 50%. but as I described there is a bigger problem...

##### Share on other sites

I thought it could be solved with this (led by grumpy) but it doesnt work and idk why actually:

```0.5 * count (thisList select{[getNumber (configfile >> "CfgVehicles" >> typeOf _x >> "side")] call BIS_fnc_sideType == east}) >= count (thisList select {side _x == east})
```
EDIT: condition is true if all easts r dead... idk why Edited by sarogahtyp

deleted

##### Share on other sites

I thought it could be solved with this (led by grumpy) but it doesnt work and idk why actually:

```0.5 * count (thisList select{[getNumber (configfile >> "CfgVehicles" >> typeOf _x >> "side")] call BIS_fnc_sideType == east}) >= count (thisList select {side _x == east})
```
EDIT: condition is true if all easts r dead... idk why

Looks like the count value is being overwritten when it goes to the second part: "count (thisList select {side _x == east})"

And so, the trigger compare the same values...it's not being stored in one side and compared to the other side value.

That's why I think this could only be solved by a script, where some variable sotres the first value and the trigger compares to it's own count.

##### Share on other sites

Looks like the count value is being overwritten when it goes to the second part: "count (thisList select {side _x == east})"

And so, the trigger compare the same values...it's not being stored in one side and compared to the other side value.

That's why I think this could only be solved by a script, where some variable sotres the first value and the trigger compares to it's own count.

sorry but thats nonsense.

count is not a value but a functtion and yes its returning a value but what is a condition? a condition compares 2 values and my latest condition has a value on the left and a value on the right side. both r compared by the ">=". nothing is overwritten. but there is a logical error which can be solved. it is possible to do it tzhat way without storing the initial enemy count.

##### Share on other sites

Triggers do not report dead units in thisList.

```count ( allDeadMen select { _x inArea thisTrigger && !alive _x && ( [ _x ] call BIS_fnc_objectSide isEqualTo east ) } )
>=
count ( thisList select { side _x isEqualTo east } )```
• 3

##### Share on other sites

Triggers do not report dead units in thisList.

```count ( allDeadMen select { _x inArea thisTrigger && !alive _x && ( [ _x ] call BIS_fnc_objectSide isEqualTo east ) } )
>=
count ( thisList select { side _x isEqualTo east } )```

thx for clarifying that and for BIS_fnc_objectSide :-)

##### Share on other sites

Triggers do not report dead units in thisList.

`count ( allDeadMen select { _x inArea thisTrigger && !alive _x && ( [ _x ] call BIS_fnc_objectSide isEqualTo east ) } )>=count ( thisList select { side _x isEqualTo east } )`
Didn't tested but thanks for the help larrow.

This works for 50% right? If I want like 90% of dead enemies this gets a little bit more complicated I think...

Do you think that is possible?

##### Share on other sites

Finally this is tested and working:

```0.8 * ( count ( allDeadMen select { _x inArea thisTrigger &&  ( [getNumber (configfile >> "CfgVehicles" >> typeOf _x >> "side")] call BIS_fnc_sideType == east ) } ) + count ( thisList select { side _x == east })) >= count ( thisList select { side _x == east })
```

or this is the same:

```0.8 * count ((allDeadMen select { _x inArea thisTrigger &&  ( [getNumber (configfile >> "CfgVehicles" >> typeOf _x >> "side")] call BIS_fnc_sideType == east ) } ) + (thisList select { side _x == east })) >= count ( thisList select { side _x == east })
```

0.8 is the the part of living enemies means 80 % r living and 20% have to be dead.
for activating the trigger when 90% r killed u ve to choose 0.1 as factor.

@larrow: I didnt get it work with BIS_fnc_objectSide. count always returned 1 while counting dead enemies.

and here is the solution with saving the enemy count at mission start. this will work with an enabled cleanup script as well:

```your_global_init_count = count (allUnits select {side _x == east && _x inArea your_trigger_name});
```
```count ( thisList select { side _x == east } <= 0.1 * your_global_init_count
```
• 1

##### Share on other sites

@larrow: I didnt get it work with BIS_fnc_objectSide. count always returned 1 while counting dead enemies.

I've just done some tests with BIS_fnc_objectSide, although the function is setup properly, to return a units proper side(side of the group it belongs to) if param 1 is false/not supplied, it seems as though dead units are decoupled from their group very quickly, making them grpNull which will make objectSide return side unit which as we know a dead unit is CIV.

So objectSide is ok for use in things like killed EH but checking a unit that has been dead for a few seconds will return CIV.

As a note this..

`getNumber (configfile >> "CfgVehicles" >> typeOf _x >> "side")] call BIS_fnc_sideType`
and

`[_unit,true] call BIS_fnc_objectSide`
do the same thing, by getting a units config side, and the latter can make code shorter and easier to read.

##### Share on other sites

Finally this is tested and working:

```0.8 * ( count ( allDeadMen select { _x inArea thisTrigger &&  ( [getNumber (configfile >> "CfgVehicles" >> typeOf _x >> "side")] call BIS_fnc_sideType == east ) } ) + count ( thisList select { side _x == east })) >= count ( thisList select { side _x == east })
```

or this is the same:

```0.8 * count ((allDeadMen select { _x inArea thisTrigger &&  ( [getNumber (configfile >> "CfgVehicles" >> typeOf _x >> "side")] call BIS_fnc_sideType == east ) } ) + (thisList select { side _x == east })) >= count ( thisList select { side _x == east })
```

0.8 is the the part of living enemies means 80 % r living and 20% have to be dead.

for activating the trigger when 90% r killed u ve to choose 0.1 as factor.

@larrow: I didnt get it work with BIS_fnc_objectSide. count always returned 1 while counting dead enemies.

and here is the solution with saving the enemy count at mission start. this will work with an enabled cleanup script as well:

```your_global_init_count = count (allUnits select {side _x == east && _x inArea your_trigger_name});
```
```count ( thisList select { side _x == east } <= 0.1 * your_global_init_count
```

Hi, I've tested the first two codes but they didn't work.

Just to clarify, I put them on the condition box of a trigger activated by none but the trigger activated every time :/

My trigger pic:

http://imgur.com/Df1K0Md

EDIT: *WORKING*, the problem was with the NONE activation, thank you!!!!! :218:  :ok:

About the third code, I tried to put this on my init.sqf:

```counting_var = count (allUnits select {side _x == east && _x inArea trigger01});
```

and this on my trigger condition box:

```count ( thisList select { side _x == east } <= 0.1 * counting_var
```

but no success.

:(  :(

##### Share on other sites

sorry but im on holliday in greek now. cant test anything here. maybe larrow does.

##### Share on other sites

Hi, I've tested the first two codes but they didn't work.

Just to clarify, I put them on the condition box of a trigger activated by none but the trigger activated every time :/

My trigger pic:

http://imgur.com/Df1K0Md

EDIT: *WORKING*, the problem was with the NONE activation, thank you!!!!! :218: :ok:

About the third code, I tried to put this on my init.sqf:

`counting_var = count (allUnits select {side _x == east && _x inArea trigger01});`
and this on my trigger condition box:

`count ( thisList select { side _x == east } <= 0.1 * counting_var`
but no success.

:( :(

try this from debug console after mission start to check ur variable content:

systemChat str counting_var;

edit: missed a brace. this should work

count ( thisList select { side _x == east } )<= 0.1 * your_global_init_count

• 1

##### Share on other sites

is this really solved??

if so, does it work for all Enemy Infantry?

If it does why am i getting this error message "Error missing ]" when using this code.

_v_markername = _missionabrev + "Marker_1";

SMEndTask = [west,[_v_taskname],["SideMission Update: Kill remaining Hostiles!", "SideMission Update: Kill remaining Hostiles!", "SideMission Update: Kill remaining Hostiles!"],getMarkerPos _v_markername,true,5,true,"attack",True] call BIS_fnc_taskCreate;

your_global_init_count = count (allUnits select {side _x == east && _x inArea your_trigger_name});
count ( thisList select { side _x == east } )<= 0.1 * your_global_init_count;

SMTrg_alldead = createTrigger ["EmptyDetector", getMarkerPos _v_markername];
SMTrg_alldead setTriggerArea [500, 500, 0, false];
SMTrg_alldead setTriggerStatements ["0.1 * ( count ( allDeadMen select { _x inArea thisTrigger &&  ( [getNumber (configfile >> "CfgVehicles" >> typeOf _x >> "side")] call BIS_fnc_sideType == east ) } ) + count ( thisList select { side _x == east })) >= count ( thisList select { side _x == east });" ,  "SMEndTask = ['" + _v_taskname + "', 'SUCCEEDED',true] spawn BIS_fnc_taskSetState; ['" + _missionabrev + "', '" + _taskid + "']  call TLS_fnc_spawnEndSMFunc;  ", ""];
SMTrg_alldead setTriggerTimeout [1, 1, 1, false]

Edited by LifeSnatcher
spelling and grammer

##### Share on other sites

Hey! Yes. It was solved at the time.

You can check my trigger picture to see how I used the code:

If I remember correctly I putted the condition code inside a trigger activated by None.

I don't remeber right now if I set up some countdown (You can try it if it doesn't work)

Quote

0.8 * ( count ( allDeadMen select { _x inArea thisTrigger && ( [getNumber (configfile >> "CfgVehicles" >> typeOf _x >> "side")] call BIS_fnc_sideType == east ) } ) + count ( thisList select { side _x == east })) >= count ( thisList select { side _x == east })

To work with all enemy infrantry just make sure that the trigger is encircling all of them.

Sorry for the late response.

• 1

##### Share on other sites
33 minutes ago, luks7n said:

Sorry for the late response.

Nah man...22 months is about right..average I would say. 🤣🤣🤣🤣

PS: I've had a similar issue, HERE, and was solved slightly differently:

```Just to recap... I had this working with a trigger:

-variable name: trig01

-activation OPFOR

-not present

-condition:

this or { (count thisList) <= (thisTrigger getVariable ["minAliveUnitsNumber", 0]) }
On Act:- whatever you need to exec.

In the init.sqf:

_unitsNumber = { !(isPlayer _x) and { (side _x) == opfor } and { _x inArea trg01 } } count allUnits;

trg01 setVariable ["minAliveUnitsNumber", ceil (0.2 * _unitsNumber)];```

• 3
• 1