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

Adding units to a periodic spawner

Status
Not open for further replies.
Level 7
Joined
May 30, 2018
Messages
290
Hello,

could somebody help me with a trigger, that does that after a specific type of building is built, a specific type of unit gets added to the next spawning wave. E.g.: You build the building and in the next spawning wave the unit type attached to that building type will also spawn in that wave.

Kind regards,
Mechcash
 
Level 3
Joined
Mar 18, 2020
Messages
20
The easiest way to do this is with a periodic timer and a unit group. These two triggers make a Footman spawn at every Barracks every 30 seconds.

Initialize the spawn timer:
  • Initialize Timer
    • Events
      • Time - Elapsed game time is 5.00 seconds
    • Conditions
    • Actions
      • Countdown Timer - Start SpawnTimer as a Repeating timer that will expire in 30.00 seconds
      • Countdown Timer - Create a timer window for SpawnTimer with title Spawns in:
      • Countdown Timer - Show (Last created timer window)
Where "SpawnTimer" is a Timer variable.

Spawn Footmen at every Barracks:
  • Spawn Units
    • Events
      • Time - SpawnTimer expires
    • Conditions
    • Actions
      • Set VariableSet SpawnUnitGroup = (Units of type Barracks)
      • Unit Group - Pick every unit in SpawnUnitGroup and do (Actions)
        • Loop - Actions
          • Set VariableSet TempPoint = (Position of (Picked unit))
          • Unit - Create 1 Footman for (Owner of (Picked unit)) at TempPoint facing Default building facing degrees
          • Unit - Order (Last created unit) to Attack-Move To (TempPoint offset by 10000000.00 towards 0.00 degrees.)
      • Custom script: call RemoveLocation (udg_TempPoint)
      • Custom script: call DestroyGroup (udg_SpawnUnitGroup)
Where "TempPoint" is a Point variable and "SpawnUnitGroup" is a Unit Group variable.

The "Order (Last created unit)" is just a command that orders the spawned unit to move directly to the right to the end of the map (since 0 degrees is West). There are many ways to issue the order to attack with a wave. This is just one example.

The two custom scripts at the end are to prevent leaks. If you don't include them, your map will get laggy and triggers won't function properly after a while. Check out this post (Triggers - Memory Leaks and Custom Scripts) on memory leaks for more information on that.
 
Last edited:
Level 6
Joined
Dec 31, 2017
Messages
138
Global variables:
TempInteger, TempPlayer, TempPoint, TempUnitTypeID = integer, player, point and integer
Buildings2Units and Waves = hashtables
WaveUnitTypeIDs = integer array
WaveUnitTypeIDsMax = integer, max index of said array

At Map Init:
  • Actions
    • Custom script: set udg_Waves = InitHashtable()
    • Custom script: set udg_WaveUnitTypeIDs[0] = 'hfoo'
    • Custom script: set udg_WaveUnitTypeIDs[1] = 'hpea'
    • Set WaveUnitTypeIDsMax = 1
    • Custom script: set udg_Buildings2Units = InitHashtable()
    • Custom script: call SaveInteger(udg_Buildings2Units, 0, 'hbar', 'hfoo')
    • Custom script: call SaveInteger(udg_Buildings2Units, 0, 'hhou', 'hpea')
When a unit finishes construction:
  • Actions
    • Custom script: set udg_TempInteger = LoadInteger(udg_Buildings2Units, 0, GetUnitTypeId(GetTriggerUnit()))
    • If (TempInteger Less than or equal to 0) then do (Skip remaining actions) else do (Do nothing)
    • Game - Display to (All players) the text: (String(TempInteger))
    • Hashtable - Save ((Load 0 of TempInteger from Waves) + 1) as 0 of TempInteger in Waves
Spawn a wave (you can alter TempPlayer and TempPoint any way you want):
  • For each (Integer A) from 0 to WaveUnitTypeIDsMax, do (Actions)
    • Loop - Actions
      • Set TempUnitTypeID = WaveUnitTypeIDs[(Integer A)]
      • Set TempInteger = (Load 0 of TempUnitTypeID from Waves)
      • Set TempPlayer = Player 1 (Red)
      • Set TempPoint = (Center of (Playable map area))
      • Custom script: call CreateNUnitsAtLoc(udg_TempInteger, udg_TempUnitTypeID, udg_TempPlayer, udg_TempPoint, bj_UNIT_FACING)
      • Custom script: call RemoveLocation(udg_TempPoint)
 
Status
Not open for further replies.
Top