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

Spawning units

Status
Not open for further replies.
Level 2
Joined
Apr 7, 2013
Messages
8
Trying to make a trigger so that when a hero is in a region units starts to spawn. I have set so every 15 sec a new unit spawns, but need help so if 10 units have been spawned no more spawn until there is less then 10 units again.

Right now i got so far that it spawn only up to 10, but when one dies no new ones spawn
 
Level 6
Joined
Aug 28, 2015
Messages
213
There are two ways to this
Either check every time when you want to spawn a unit, if there is less then 10 and spawn one else just skip the sequence this time.
Or
Add a trigger with the generig unit dies
Event
Check if the unit is in the region and check if there are less then 10 left, if so, turn the spawn trigger on again.
Can you post your triggers to see how you have done it?
 
Level 20
Joined
Feb 23, 2014
Messages
1,264
I believe that something like this might be the simplest solution.

First this:

  • Events
    • Time - Every 15 seconds of game time
  • Conditions
    • (<spawn region> contains <hero unit>) Equal to True
    • (<hero unit> is alive) Equal to True
    • (Number of units in <spawned units group>) Less than 10
  • Actions
    • Set SPAWN = <location>
    • Unit - Create 1 <unit type> for <owner of spawned units> at SPAWN facing <desired facing>
    • Custom script: call RemoveLocation (udg_SPAWN)
    • Unit Group - Add (Last created unit) to <spawned units group>
And then this:

  • Events
    • Unit - A unit owned by <owner of spawned units> Dies
  • Conditions
  • Actions
    • Unit Group - Remove (Triggering unit) from <spawned units group>
The reason why the second trigger is necessary is because the game counts dead units as being a part of the unit group until they despawn.

Obviously, the triggers above only work periodically, i.e. it will attempt to spawn a unit every 15 seconds, thus if a unit dies like 5 second after the trigger was run, you will still have to wait those 10 second until the trigger is fired again.

If you want something else, for example the triggers spawning a new unit the instant a "slot" is available and then checking every 15 seconds or restarting the periodic timer every time a "slot" becomes available, let me know and I'll cook something up for ya'.
 
Last edited:
Status
Not open for further replies.
Top