• 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.
  • It's time for the first HD Modeling Contest of 2025. Join the theme discussion for Hive's HD Modeling Contest #7! 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 71
Joined
Aug 10, 2018
Messages
7,561
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