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

[Trigger] Automatic Unit Spawn

Status
Not open for further replies.

mik

mik

Level 4
Joined
Dec 13, 2007
Messages
59
Hey guys,

i wanted to have some Buildings automatically spawn a certain Unit every X seconds (got a continuous timer).

The unit should belong to the player who built the building, and should be of the right type (tank factory spawns a tank, airfield a plane and so on). It should not just be trained there, because i want all the units to spawn together in waves.

Somehow, i dont get it done, nor was i finding a thread for that :sad:
 
Level 5
Joined
Jan 5, 2008
Messages
145
hmmm idk what exactly you want but i think i got the most of it.

what i would do is add the buildings to a unit group.than every 10 secs pick every unit in the unit group and spawn a unit at the picked unit. err..maybe this will help
  • Spawn Every 10 sec
    • Events
      • Time - Every 10.00 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in Building1 and do (Actions)
        • Loop - Actions
          • Unit - Create 1 Footman for (Owner of (Picked unit)) at (Position of (Picked unit)) facing Default building facing degrees
building 1 is a barracks

when i create it i also put for the owner for picked unit so it spawns for the correct player.
hope that helped.

*EDIT* and here is how you would add the building to the unit group
  • Barrack Add To Unit Group
    • Events
      • Unit - A unit Finishes construction
    • Conditions
      • (Unit-type of (Constructed structure)) Equal to Barracks
    • Actions
      • Unit Group - Add (Constructed structure) to Building1
Hope that helped even more
 

mik

mik

Level 4
Joined
Dec 13, 2007
Messages
59
Thanks, that helped me to get it done as i wanted it to be :)

+rep, solved
 
Level 8
Joined
Jun 1, 2008
Messages
341
That trigger will leak causing minor lag after a while (well.. Maybe)
In any case. To remove the leak use the following code (it also condenses the whole trigger down to just 1):

  • Spawn Every 10 sec
  • Events
    • Time - Every 10.00 seconds of game time
  • Conditions
  • Actions
    • Set TempGroup = (Units in (Playable map area) matching (((Unit - Type of (Matching Unit)) Equal to ('Spawning Structure'))))
    • Unit Group - Pick every unit in TempGroup and do (Actions)
      • Loop - Actions
        • Set TempPoint = (Position of (Picked Unit))
        • Unit - Create 1 Footman for (Owner of (Picked unit)) at TempPoint facing Default building facing degrees
        • Custom script: call RemoveLocation(udg_TempPoint)
  • Custom script: call DestroyGroup(udg_TempGroup)
P.S. make sure that you actually put the type of building you want to spawn units in there. Not just 'Spawning Structure' as I have. If you want to use more than one spawning structures. Just use the Or statement in the line where we set the TempGroup.
 
Status
Not open for further replies.
Top