Unit spawning help


New Member
Reaction score
I'm attempting to make buildings that spawn units over and over (not in a region, but have the building do so) but it also detect how many units it has placed. I want this because, I don't want it to be able to spawn more then 10 at a time.

Example: Building 1 has spawned 10 units. No more units can spawn until a unit is killed...so if 1 unit is killed, another unit is spawned...if 4 units are killed, then 4 more are spawned.

Also, I would like the units to be trained 1 by 1, not just spawn all at once.
Thanks in advance! :thup:
The unit kill idea could bug.. someone could spawn 10 units, kill them, and then revive them and then have 20 units total, etc, etc.
It will be controlled, no one but computers will be spawning units, and no hero/unit has a revive.
You could use hashtables and save the buildings ID in the unit.

Give the building the ability to produce the unit
This is freehand sorry.

every x seconds
Pick every unit = building
set group = units with ID = buildings
if number of units in group less than 10 then
order picked building to produce unit

building produces unit
save ID to hashtable
order unit to do what ever
If ((Number of units in (Units of type Zombie)) Less than 10) then do (Unit Group - Pick every unit in (Units of type Grave) and do (Unit - Order (Matching unit) to train/upgrade to a Zombie)) else do (Do nothing)

Is what I have so far. But I cant seem to get what you have in the editor. Mind showing me what it should look like?
  • Untitled Trigger 001
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
    • Actions
      • Set building_group = (Units in (Playable map area) matching (((Triggering unit) is A structure) Equal to True))
      • Unit Group - Pick every unit in building_group and do (Actions)
        • Loop - Actions
          • Set zombie_group = (Units in (Playable map area) matching ((Custom value of (Matching unit)) Equal to (Key (Picked unit))))
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Number of units in zombie_group) Less than 10
            • Then - Actions
              • Unit - Order (Picked unit) to train/upgrade to a Dalaran Mutant
            • Else - Actions
      • Custom script: call DestroyGroup(udg_building_group)
      • Custom script: call DestroyGroup(udg_zombie_group)

  • Untitled Trigger 002
    • Events
      • Unit - A unit Finishes training a unit
    • Conditions
    • Actions
      • Unit - Set the custom value of (Trained unit) to (Key (Triggering unit))

I did this with custom value but if you are using them, you could just use a hashtable.
Quick question, will the trigger you made work for 10 units PER building? If so I will just use it, or does it do 10 of that kind of unit?
By setting the custom value of every unit that gets trained, you effectively "tag" the trained unit. So if the number of "tagged" units (units whose custom value is the same as the picked structure) is less than the specified value, then that means there is room for more units to be trained.

Though the condition should be
(((Matching unit) is A structure) Equal to True))
instead of
(((Triggering unit) is A structure) Equal to True))

Maybe this thread would help, though I don't think it's very efficient.
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online


      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.