OFPEC Forum

Editors Depot - Mission Editing and Scripting => OFP - Editing/Scripting General => Topic started by: Kaio23 on 28 Apr 2005, 20:54:57

Title: Detecting if 50% of an enemy is dead in an area
Post by: Kaio23 on 28 Apr 2005, 20:54:57
This condition isn't working correctly:

Code: [Select]
"!Alive _x" count thislist >= 0.5 *Count thislist
Any ideas? It activates when all the enemies are dead.

And yes, I have the trigger set to "East Present"
Title: Re:Detecting if 50% of an enemy is dead in an area
Post by: THobson on 28 Apr 2005, 21:16:36
thislist only contains the living unit in the trigger area.  So the only time your condition can be true is when the list is empty.

To do what you want you would need to have a list of all those that were in the area at the start and then check thislist of your trigger against 50% of the list that was originally there.
Title: Re:Detecting if 50% of an enemy is dead in an area
Post by: Kaio23 on 28 Apr 2005, 21:27:24
 :o

So I need to name all my units and put them into a notepad file in my mission directory?
Title: Re:Detecting if 50% of an enemy is dead in an area
Post by: THobson on 28 Apr 2005, 21:55:09
I didn't say that.

Say you want to do this for all of the east units in your mission.  Create a large trigger to cover them all set it to east present and in the activation field put

AllEast = + thislist

You have now created an array of all the east units at the start of the mission (neglect to put in the + sign and this list will constantly update as units die, with the + sign it is frozen for the duration of the mission.)

Then in the trigger you refer to above have the condition

({alive _x} count thislist) < 0.5* (count AllEast)

I have not tested this and when I want to do things like this I use scripts, but the above should give you some idea of the sort of thing to do.

NB:

If it works - do an experiment.  Take out the + in + thislist, and I predict it will stop working.
Title: Re:Detecting if 50% of an enemy is dead in an area
Post by: Kaio23 on 28 Apr 2005, 23:07:31
That did it, thanks :)
Title: Re:Detecting if 50% of an enemy is dead in an area
Post by: dmakatra on 29 Apr 2005, 06:56:21
WTH? +? How'd you know that?

:beat: *Gets Shot* :beat:
Title: Re:Detecting if 50% of an enemy is dead in an area
Post by: THobson on 29 Apr 2005, 07:51:59
From comref:

Quote
Array assignment

Description:
Assignment used on arrays assigns only pointer to the same array to the target variable. When b is an array, after executing a = b both a and b represent the same array. When b is changed, a is changed as well. One particular situation that can lead to this behaviour is aList = list sensor_name. You can force creating a copy of array by using unary operator +Array

So without the + AllEast will just be a pointer to the list belonging to the trigger.  With the + a whole new copy is made and AllEast points to that.

Ta da!
Title: Re:Detecting if 50% of an enemy is dead in an area
Post by: macguba on 29 Apr 2005, 10:34:14
A classic example of why you must read the comref from cover to cover more than once.