• 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.

Unit Spawns

Status
Not open for further replies.
Level 4
Joined
Apr 16, 2012
Messages
83
In my map you have a builder who builds buildings which will then spawn a unit every 30 seconds (doesnt matter when it was built, its just a 30 second interval where all the units are spawned from each building). How would I go about doing this? Each building will have upgrades and spawn different units, and i also want them to spawn while the building is under construction.
 
Level 14
Joined
Jul 12, 2011
Messages
1,371
With this trigger you will be able to train a unit at a building in a specified location.
  • Unit Spawn
    • Events
      • Time - Every 30.00 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in (Units in Region 001 <gen>) and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Unit-type of (Picked unit)) Equal to Barracks
            • Then - Actions
              • Unit - Order (Picked unit) to train/upgrade to a Footman
            • Else - Actions
Region 001 will be a region that you create wherever you want.
Footman and Barracks are units I placed. Use whatever unit you want.
In order for this to work you must set the train time of your unit (e.g. Footman) to Zero.
 
Level 28
Joined
Jan 26, 2007
Messages
4,789
This seems to be an easy method:

Setup Trigger

Spawn Trigger


  • Spawn Setup
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set spawnCounter = (spawnCounter + 1)
      • Set spawnBuildingType[spawnCounter] = Farm
      • Set spawnUnitType[spawnCounter] = Peasant
      • -------- --- --------
      • Set spawnCounter = (spawnCounter + 1)
      • Set spawnBuildingType[spawnCounter] = Barracks
      • Set spawnUnitType[spawnCounter] = Footman
      • -------- --- --------
      • Set spawnCounter = (spawnCounter + 1)
      • Set spawnBuildingType[spawnCounter] = Blacksmith
      • Set spawnUnitType[spawnCounter] = Rifleman
      • -------- --- --------
      • Set spawnCounter = (spawnCounter + 1)
      • Set spawnBuildingType[spawnCounter] = Gryphon Aviary
      • Set spawnUnitType[spawnCounter] = Gryphon Rider
  • Spawn
    • Events
      • Time - Every 30.00 seconds of game time
    • Conditions
    • Actions
      • For each (Integer loopInt) from 1 to spawnCounter, do (Actions)
        • Loop - Actions
          • Custom script: set bj_wantDestroyGroup = true
          • Unit Group - Pick every unit in (Units of type spawnBuildingType[loopInt]) and do (Actions)
            • Loop - Actions
              • Set tempLoc1 = (Position of (Picked unit))
              • Unit - Create 1 spawnUnitType[loopInt] for (Owner of (Picked unit)) at tempLoc1 facing Default building facing degrees
              • Custom script: call RemoveLocation( udg_tempLoc1 )
The trigger "Spawn Setup" is the most important one for you.
It uses 3 variables: integer spawnCounter, unit-type array "spawnBuildingType" and unit-type array "spawnUnitType".
spawnBuildingType is the building that will spawn the units.
spawnUnitType is the unit-type of the unit that gets spawned.

In the second trigger you might want to change the event (if you want "Timer expires" for example), or/and change the spawn location ("tempLoc1") if they should all spawn at a certain location, not at the building itself.
 
Level 4
Joined
Apr 16, 2012
Messages
83
that won't work for me destroyer, as having them trained from the building would mean u could just click on them yourself and spam them.

ap0clypse, i dont really understand your triggers :( could you explain each part?
 
Level 28
Joined
Jan 26, 2007
Messages
4,789
Yeah, sure.
Note that I don't explain arrays and loops in this post. If you need info on that,

So in the Setup-trigger you just set up a simple table. That means you're using arrayed variables to link 2 things together.
In this case, you link the building and the unit together (so you can easily know which building creates which unit).
spawnBuildingType[1] creates spawnUnitType[1]
spawnBuildingType[2] creates spawnUnitType[2]
spawnBuildingType[3] creates spawnUnitType[3]
...
Tables like this are very common and useful.


In the next trigger, we loop through the entire table (from 1 to the amount of buildings we have).
Every time the integer increases by 1, we pick all buildings of type spawnBuildingType[looped integer].
Because we linked those units together with the ones they create (see previous paragraph), we know exactly which unit type to spawn (spawnUnitType[looped integer]).


The custom scripts and the "set tempLoc1" are used to remove memory leaks (memory leaks slow down the game, you always need to remove them).
 
Status
Not open for further replies.
Top