• 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.
  • The Hive's 22nd Icon Contest: Creep Abilities is now concluded, time to vote for your favourite set of icons! Click here to vote!
  • ✅ The POLL for Hive's Texturing Contest #34 is OPEN! Vote for the TOP 3 SKINS! 🔗Click here to cast your vote!
  • ✅ The POLL for Hive's Techtree Contest #20 is OPEN! Vote for the TOP 3 FACTIONS! 🔗Click here to cast your vote!

Enemy on Map Counter

Status
Not open for further replies.
Level 1
Joined
Dec 18, 2019
Messages
2
Hey there everyone.
Im looking to make a counter that displays how many enemies are on the map at any given time.
How would i go about setting something like this up?
 
That will count dead units. Will have to remove them when they die. Sabe's solution is best if the map is very large and there would be lots of units at a time. If there are only a few then you can count dynamically by picking every unit in the map owned by each player and use these counts to periodically update a multiboard/leaderboard.

All About Multiboards
Leaderboards
 
Or, if you have an unit indexer (which I recommend), you can just add unit upon indexing and remove it when it dies. With Bribe's unit indexer it could look like this

On Create
  • Events
    • Game - UnitIndexEvent becomes Equal to 1.00
  • Conditions
  • Actions
    • Unit Group - Add UDexUnits[UDex] to PlayerUnits[(Player number of (Owner of UDexUnits[UDex]))]
On death
  • Events
    • Unit - A unit Dies
  • Conditions
  • Actions
    • For each (Integer A) from 1 to (Number of players), do (Actions)
      • Loop - Actions
        • If (((Dying unit) is in PlayerUnits[(Integer A)]) Equal to True) then do (Unit Group - Remove (Dying unit) from PlayerUnits[(Integer A)]) else do (Do nothing)
You actually don't even need to have unit groups if you just want to count them. You can just have an integer array and +1 when a unit is created and -1 when a unit dies, but you might have other uses for storing them in a unit group.
 
Last edited:
There might be precreated natives for that:
JASS:
constant native GetPlayerUnitCount      takes player whichPlayer, boolean includeIncomplete returns integer
constant native GetPlayerTypedUnitCount takes player whichPlayer, string unitName, boolean includeIncomplete, boolean includeUpgrades returns integer
constant native GetPlayerStructureCount takes player whichPlayer, boolean includeIncomplete returns integer

Edit: They also have GUI ports:
  • Conditions
    • (Count non-structure units controlled by Player 1 (Red) (Exclude incomplete units)) Equal to 0
    • (Count structures controlled by Player 1 (Red) (Exclude incomplete structures)) Equal to 0
When you want to know the amount of one specific unitcode you can also ask for the current techlevel of that unitcode that would also include units counting as equals
JASS:
constant native GetPlayerTechCount      takes player whichPlayer, integer techid, boolean specificonly returns integer
 
There might be precreated natives for that:
JASS:
constant native GetPlayerUnitCount      takes player whichPlayer, boolean includeIncomplete returns integer
constant native GetPlayerTypedUnitCount takes player whichPlayer, string unitName, boolean includeIncomplete, boolean includeUpgrades returns integer
constant native GetPlayerStructureCount takes player whichPlayer, boolean includeIncomplete returns integer

Edit: They also have GUI ports:
  • Conditions
    • (Count non-structure units controlled by Player 1 (Red) (Exclude incomplete units)) Equal to 0
    • (Count structures controlled by Player 1 (Red) (Exclude incomplete structures)) Equal to 0
Doesn't this include for example dead or locust units though?
 
Status
Not open for further replies.
Back
Top