• 🏆 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!

How to get the total Health Points of units in a unit group?

Status
Not open for further replies.

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,546
For Current HP:
  • Get Total Current HP
    • Events
    • Conditions
    • Actions
      • Set Variable TempGroup = (Units in (Playable map area) matching ((Unit-type of (Matching unit)) Equal to Footman))
      • Set Variable HPCurrent = 0.00
      • Unit Group - Pick every unit in TempGroup and do (Actions)
        • Loop - Actions
          • Set Variable HPCurrent = (HPCurrent + (Life of (Picked unit)))
For Max HP:
  • Get Total Max HP
    • Events
    • Conditions
    • Actions
      • Set Variable TempGroup = (Units in (Playable map area) matching ((Unit-type of (Matching unit)) Equal to Footman))
      • Set Variable HPMax = 0
      • Unit Group - Pick every unit in TempGroup and do (Actions)
        • Loop - Actions
          • Set Variable HPMax = (HPMax + (Max HP of (Picked unit)))
HPCurrent is a Real variable and HPMax is an Integer variable.

Don't forget to clean up the memory leak after looping over the group:
  • Custom script: call DestroyGroup(udg_TempGroup)
^ This is only necessary if the Unit Group is temporary. In other words, destroy it if you don't need to keep tracking the units inside.
 
Last edited:
Status
Not open for further replies.
Top