• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[Solved] Living units detection

Status
Not open for further replies.
Level 5
Joined
Jun 12, 2016
Messages
74
Hi guys, sorry for the noobness here, but I want a condition that detect the number of living units in a unit group (integer right?). GUI pls.

Number of units in a unit group can't count the living ones, it counts the dead aswell.
 
Level 45
Joined
Feb 27, 2007
Messages
5,578
You just need to loop through all of them and increase some sort of counter variable for each alive unit:
  • Set COUNT = 0
  • Set GROUP = Units in (Playable Map Area)
  • Unit Group - Pick every unit in GROUP and do (Actions)
    • Loop - Actions
      • If (All conditions are true) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Current life of (Picked Unit)) greater than 0.405 //units die at 0.405 hp, not at 0 or 1. It's weird, just go with it.
        • Then - Actions
          • Set COUNT = COUNT + 1
        • Else - Actions
  • Custom script: call DestroyGroup(udg_GROUP) //cleans the group leak; change the variable name to match yours but keep the udg_ prefix
  • -------- here COUNT is how many alive units were in GROUP --------
 
Level 5
Joined
Jun 12, 2016
Messages
74
upload_2018-11-13_17-6-26.png


Thanks, I'll test it, but I have another question regarding the group leak, if I set a group to a variable and recicle it, will it leak?
 
Level 45
Joined
Feb 27, 2007
Messages
5,578
You can 'recycle' the group by using the "Unit Group - Remove all units from GROUP" action. This clears it so new units can be added later. However, you can only add units to it using the "Unit Group - Add UNIT to GROUP" action; if you try to 'add' units like "Set GROUP = Units in (Playable map area)" it will create a new group, assign it to the GROUP variable, and 'leak' the group that was already stored in GROUP.

Calling DestroyGroup() isn't really recycling, but it does remove the leak.
 
Status
Not open for further replies.
Top