| 06-12-2006, 11:12 PM | #1 |
I can't seem to find the correct combination of trigger actions to get the number of units of a specific type in a unitgroup. I've created a unitgroup variable that I use to keep track of units created during gameplay. I'm trying to count the number units of a specific type in a unit group, but none of the cascading options I've found give a count for unit types except for total player owned or some region. Thanks, |
| 06-13-2006, 02:58 AM | #2 |
Pick every unit in region(region) and do (set picked units to (unitgroup)). |
| 06-13-2006, 03:49 AM | #3 |
If I get your question correctly, you should loop through the unitgroup, comparing if the picked unit is the unittype of what you want an increment a local variable. |
| 06-13-2006, 04:13 AM | #4 |
Thanks, but what I'm really looking for is a count of a specific type of unit in a unitgroup. example: Number of units in (Units in (MyUnitGroup) matching (((Matching Unit) is Unit-Type archer) equals True)) Unfortunately, I can't find or figure out how to construct a trigger like the example. It doesn't exist. |
| 06-13-2006, 04:16 AM | #5 |
ya you would do something like: local integer x = 0 Pick every unit in MyUnitGroup matching Matching unit is Unit-Type archer equals true x ++ This is just psuedocode cause its too late for me to feel like opening World Editor. Basically, everytime it picks another unit matching that condition, it will increment x. So at the end, x will be your count. |
| 06-13-2006, 05:15 AM | #6 |
You will need to use a global variable because forgroup does its work through callback functions. |
| 06-13-2006, 05:39 AM | #7 |
Alternatively you could just copy the group, then check if the first unit in the copy is of the type, if so add 1, otherwise remove him from the group. Keep doing this until the group is out of elements. (Gui sucks, so you can only do for loops for integers in it :/) |
| 06-13-2006, 10:08 PM | #8 |
I did finally come up with a combination, rather bulky, but do-able. Set UnitCount = (Number of units in (Units owned by Player 1 (Red) matching ((((Matching unit) is in MyUnitGroup) Equal to True) and (((Unit-type of (Matching unit)) Equal to Archer) and (((Matching unit) is alive) Equal to True))))) Not sure if the combination above or the picked unit suggestions would execute faster? Thanks, for all of the feedback. |
