• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[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 39
Joined
Feb 27, 2007
Messages
4,992
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 39
Joined
Feb 27, 2007
Messages
4,992
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