• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

[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 40
Joined
Feb 27, 2007
Messages
5,124
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 40
Joined
Feb 27, 2007
Messages
5,124
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