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

Count number of Ancients on the map

Status
Not open for further replies.
Level 25
Joined
Sep 26, 2009
Messages
2,387
There are more ways to do this.
The simplest but the worst (efficiency-wise) would be to use this whenever you need to find out how many ancients are ingame:
  • -------- the custom script below takes care of memory leaks --------
  • Custom script: set bj_wantDestroyGroup = true
  • Unit Group - Pick every unit in (Units in (Playable map area) matching ((((Matching unit) is An Ancient) Equal to True) and (((Matching unit) is alive) Equal to True))) and do (Actions)
    • Loop - Actions
      • Set count = (count + 1)
The problem with the above is if you have too many units in your map, then the game will pick every unit in your map, check if its ancient and put it inside the unit group, then it will iterate through each unit inside the unit group and increase value in "count" variable by 1.
Unit groups are also heavy process, so creating them in very quick succession one after another may cause lags.

More efficient way is imo by having 1 variable specifically used to keep track of ancients. This will require more (but simple) triggers.
  • Map Ini
    • Events
      • Map initialization
    • Conditions
    • Actions
      • -------- the custom script below takes care of memory leaks --------
      • Custom script: set bj_wantDestroyGroup = true
      • Unit Group - Pick every unit in (Units in (Playable map area) matching (((Matching unit) is An Ancient) Equal to True)) and do (Actions)
        • Loop - Actions
          • Set NumberOfAncients = (NumberOfAncients + 1)
You need to do this once at map initialization.

  • Increase
    • Events
      • Unit - A unit enters (Playable map area)
    • Conditions
      • ((Triggering unit) is An Ancient) Equal to True
    • Actions
      • Set NumberOfAncients = (NumberOfAncients + 1)
  • Decrease
    • Events
      • Unit - A unit Dies
    • Conditions
      • ((Triggering unit) is An Ancient) Equal to True
    • Actions
      • Set NumberOfAncients = (NumberOfAncients - 1)

To find out if unit is an ancient, use the Boolean comparison
 
Status
Not open for further replies.
Top