• 🏆 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!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[Trigger] Spawn System Help

Status
Not open for further replies.
Level 37
Joined
Jul 22, 2015
Messages
3,485
Hey everyone! I'm trying to create a spawn system that supports multiple unit types in a wave and makes it so that the next wave doesn't spawn until all units in the previous wave have been killed. I'm having a hard time figuring out the latter and would love some insight! This isn't finished yet, so things may seem a bit off. Just ask me anything if something seems a bit off!

  • Spawn System 1
    • Events
      • Time - Elapsed game time is 2.00 seconds
    • Conditions
    • Actions
      • -------- -------------- --------
      • -------- -------------- --------
      • -------- OWNER --------
      • Set SpawnSystem_Owner = Player 1 (Red)
      • -------- ------------------- --------
      • -------- ------------------- --------
      • -------- UNIT TYPE --------
      • Set SpawnSystem_UnitType = Pig
      • -------- --------------------------------- --------
      • -------- --------------------------------- --------
      • -------- UNIT SPAWN LIMIT --------
      • Set SpawnSystem_UnitTypeLimit = 3
      • -------- -------------------------------- --------
      • -------- -------------------------------- --------
      • -------- SPAWN INTERVAL --------
      • Set SpawnSystem_SpawnInterval = 1.00
      • -------- --------------------------------------------------------- --------
      • -------- --------------------------------------------------------- --------
      • -------- SPAWN AMOUNT PER INTERVAL --------
      • Set SpawnSystem_Amount = 1
      • -------- -------------------------------- --------
      • -------- -------------------------------- --------
      • -------- SPAWN LOCATION --------
      • Set SpawnSystem_Location = (Center of Spawn 1 <gen>)
      • -------- --------------------- --------
      • -------- --------------------- --------
      • -------- SPAWN SFX --------
      • Set SpawnSystem_SFX = <Empty String>
      • -------- ------------------------------- --------
      • -------- ------------------------------- --------
      • Trigger - Run Spawn System Filter <gen> (checking conditions)
      • -------- ------------------------------------------- --------
      • -------- ------------------------------------------- --------
      • -------- Changing Variable EX --------
      • Wait 10.00 seconds
      • Set SpawnSystem_TempUTL[1] = 5
  • Spawn System 2
    • Events
    • Time - Elapsed game time is 5.00 seconds
    • Conditions
    • Actions
      • -------- -------------- --------
      • -------- -------------- --------
      • -------- OWNER --------
      • Set SpawnSystem_Owner = Player 2 (Blue)
      • -------- ------------------- --------
      • -------- ------------------- --------
      • -------- UNIT TYPE --------
      • Set SpawnSystem_UnitType = Chicken
      • -------- --------------------------------- --------
      • -------- --------------------------------- --------
      • -------- UNIT SPAWN LIMIT --------
      • Set SpawnSystem_UnitTypeLimit = 10
      • -------- -------------------------------- --------
      • -------- -------------------------------- --------
      • -------- SPAWN INTERVAL --------
      • Set SpawnSystem_SpawnInterval = 1.00
      • -------- --------------------------------------------------------- --------
      • -------- --------------------------------------------------------- --------
      • -------- SPAWN AMOUNT PER INTERVAL --------
      • Set SpawnSystem_Amount = 1
      • -------- -------------------------------- --------
      • -------- -------------------------------- --------
      • -------- SPAWN LOCATION --------
      • Set SpawnSystem_Location = (Center of Spawn 1 <gen>)
      • -------- --------------------- --------
      • -------- --------------------- --------
      • -------- SPAWN SFX --------
      • Set SpawnSystem_SFX = <Empty String>
      • -------- ------------------------------- --------
      • -------- ------------------------------- --------
      • Trigger - Run Spawn System Filter <gen> (checking conditions)
  • Spawn System Filter
    • Events
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • SpawnSystem_Counter Equal to 0
        • Then - Actions
          • Trigger - Turn on Spawn System Loop <gen>
        • Else - Actions
      • Set SpawnSystem_Counter = (SpawnSystem_Counter + 1)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • SpawnSystem_Counter Greater than SpawnSystem_IndexMax
        • Then - Actions
          • Set SpawnSystem_Index[SpawnSystem_Counter] = SpawnSystem_Counter
          • Set SpawnSystem_IndexMax = SpawnSystem_Counter
        • Else - Actions
      • Set SpawnSystem_LoopInt = SpawnSystem_Index[SpawnSystem_Counter]
      • Set SpawnSystem_TempOwner[SpawnSystem_LoopInt] = SpawnSystem_Owner
      • Set SpawnSystem_TempUT[SpawnSystem_LoopInt] = SpawnSystem_UnitType
      • Set SpawnSystem_TempUTL[SpawnSystem_LoopInt] = SpawnSystem_UnitTypeLimit
      • Set SpawnSystem_TempSI[SpawnSystem_LoopInt] = SpawnSystem_SpawnInterval
      • Set SpawnSystem_TempAmount[SpawnSystem_LoopInt] = SpawnSystem_Amount
      • Set SpawnSystem_TempLocation[SpawnSystem_LoopInt] = SpawnSystem_Location
      • Set SpawnSystem_TempSFX[SpawnSystem_LoopInt] = SpawnSystem_SFX
  • Spawn System Loop
    • Events
      • Time - Every 0.03 seconds of game time
    • Conditions
    • Actions
      • For each (Integer SpawnSystemLoop[1]) from 1 to SpawnSystem_Counter, do (Actions)
        • Loop - Actions
          • Set SpawnSystem_LoopInt = SpawnSystem_Index[SpawnSystemLoop[1]]
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • SpawnSystem_TimeLoop[SpawnSystem_LoopInt] Greater than or equal to SpawnSystem_TempSI[SpawnSystem_LoopInt]
            • Then - Actions
              • Set SpawnSystem_TimeLoop[SpawnSystem_LoopInt] = 0.00
              • For each (Integer SpawnSystemLoop[2]) from 1 to SpawnSystem_TempAmount[SpawnSystem_LoopInt], do (Actions)
                • Loop - Actions
                  • Set SpawnSystem_Group[SpawnSystem_LoopInt] = (Units in (Playable map area) matching (((Unit-type of (Matching unit)) Equal to SpawnSystem_TempUT[SpawnSystem_LoopInt]) and (((Owner of (Matching unit)) Equal to SpawnSystem_TempOwner[SpawnSystem_LoopInt]) and (((Matching unit) is alive) Equal to True))))
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • (Number of units in SpawnSystem_Group[SpawnSystem_LoopInt]) Less than SpawnSystem_TempUTL[SpawnSystem_LoopInt]
                    • Then - Actions
                      • Unit - Create 1 SpawnSystem_TempUT[SpawnSystem_LoopInt] for SpawnSystem_TempOwner[SpawnSystem_LoopInt] at SpawnSystem_TempLocation[SpawnSystem_LoopInt] facing Default building facing degrees
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • SpawnSystem_TempSFX[SpawnSystem_LoopInt] Not equal to <Empty String>
                        • Then - Actions
                          • Special Effect - Create a special effect at SpawnSystem_TempLocation[SpawnSystem_LoopInt] using SpawnSystem_TempSFX[SpawnSystem_LoopInt]
                          • Special Effect - Destroy (Last created special effect)
                        • Else - Actions
                    • Else - Actions
            • Else - Actions
              • Set SpawnSystem_TimeLoop[SpawnSystem_LoopInt] = (SpawnSystem_TimeLoop[SpawnSystem_LoopInt] + 0.03)
EDIT: I forgot to add that I also want these spawns to be endless ! I don't want to have to keep editing every single wave after another. I just want it so that X unit type spawns after XX amount of seconds, then Y unit type spawns ALONG with X unit type after YY amount of seconds. I also need them to spawn in intervals that I set in a variable (EX - Spawns 1 unit every 1 second.)
 
Last edited:
Level 25
Joined
Jul 10, 2006
Messages
3,315
1. Add all spawned units to a unit group.
2. Make a new trigger with event "unit dies" and condition "unit is in unit group" (the unit group you added all the units to).
First action should be to remove the dying unit from the unit group.
Next, check the number of units in the unit group. If it's equal to 0, that means the wave has cleared, and you can run the trigger to spawn the next one, or use a timer or such.
 
Level 37
Joined
Jul 22, 2015
Messages
3,485
1. Add all spawned units to a unit group.
2. Make a new trigger with event "unit dies" and condition "unit is in unit group" (the unit group you added all the units to).
First action should be to remove the dying unit from the unit group.
Next, check the number of units in the unit group. If it's equal to 0, that means the wave has cleared, and you can run the trigger to spawn the next one, or use a timer or such.

Thanks for the fast response! Does that mean I should remove these in the loop
  • Set SpawnSystem_Group[SpawnSystem_LoopInt] = (Units in (Playable map area) matching (((Unit-type of (Matching unit)) Equal to SpawnSystem_TempUT[SpawnSystem_LoopInt]) and (((Owner of (Matching unit)) Equal to SpawnSystem_TempOwner[SpawnSystem_LoopInt]) and (((Matching unit) is alive) Equal to True))))
  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
      • (Number of units in SpawnSystem_Group[SpawnSystem_LoopInt]) Less than SpawnSystem_TempUTL[SpawnSystem_LoopInt]
The only problem with this is that it keeps spawning and spawning instead of the limit I set.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,198
I would advise breaking it into two components. The first being the spawn system itself which is responsible for fulfilling spawn requests and making the units. The second is the wave manager which is responsible for instructing the spawn system what to make and dealing with the wave mechanics.

The spawn system consists of list of spawn requests which are all processed periodically. Each spawn request contains information such as what unit type to create, how often to create it, how many remaining to create and the group to add them to when created. The collection is implemented using parallel arrays for the members with each new request adding to the end of the list and finished requests (0 units to spawn) being replaced by the last element of the list. Different spawn rates are implemented by some form of counter system with an integer counter and interval being determined by modulo (if the modulo of the global counter with the request interval is 0 then spawn). Another timing solution would be some form of timing event queue with a dynamic timeout which is slightly more efficient but harder to implement.

The wave manager issues the spawn system with the requests for each wave. Units that are spawned get fed to it by the group reference with each spawn request (so it is responsible for tracking their liveliness). Since it knows how long it will take to spawn a wave (longest of the spawn requests), it always sleeps (probably a boolean set to false) for that timeout to make sure all units were created. Every time a unit dies and is inside the spawn group it removes it from the spawn group. Waves are advanced after the system wakes up (boolean set to true) when the spawn group is completely empty.

Wave advancement determines the what spawn requests to issue by running through a list of wave compositions. Each composition includes the wave metrics to feed the spawn system as well as the start period (when in the game it should start spawning) and end period (when in the game it should stop spawning). It iterates through all compositions in the list issuing them to the spawn system if the current period is inside their spawn period range. If the list is sorted chronologically a start and end index could be used to improve efficiency by having to process fewer elements.
 
Status
Not open for further replies.
Top