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

[Trigger] Advanced looping to spawn things for a TD

Status
Not open for further replies.
Level 2
Joined
Aug 7, 2008
Messages
14
I'm working on a TD map ATM, and having some issues doing the wave-spawning "my way".

First and foremost, the way spawning *should* work is something similar to Green Circle TD; where it doesn't just dump all the units at once and send them on their way, rather it has some kind of wait interval between creating the units.

However after examining an unprotected Green Circle TD, I noticed there's a trigger each for each wave that sets up the spawning routine; sets the unit to spawn, how many, etc.

That all is just way too much to handle, takes up a lot of space, and it too annoying to fiddle with finer points if after testing I find I need to adjust some numbers around.

So I built a nested series of loops. They go something like this (most of the udg variables should be self defining enough in name).

  • Player Group - Pick every player in PlayingPlayersGrp and do (Actions)
    • Loop - Actions
      • For each (Integer WaveSpawnIntegerA) from 1 to 50, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Wave_CurrentWave Equal to WaveSpawnIntegerA
            • Then - Actions
              • For each (Integer WaveSpawnIntegerB) from 1 to MobsToSpawnPerWave[WaveSpawnIntegerA], do (Actions)
                • Loop - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • CurrentWaveSpawnCounter Less than MobsToSpawnPerWave[WaveSpawnIntegerA]
                    • Then - Actions
                      • Set TempPoint = (Random point in PlayerSpawnRegions[(Player number of (Picked player))])
                      • Unit - Create 1 Wave_UnitTypes[WaveSpawnIntegerA] for Player 9 (Gray) at TempPoint facing Default building facing degrees
                      • Custom script: call RemoveLocation (udg_TempPoint)
                      • Set CurrentWaveSpawnCounter = (CurrentWaveSpawnCounter + 1)
                      • Wait 0.25 game-time seconds
                    • Else - Actions
            • Else - Actions
Basically the run down is to check who is playing & user controlled (the PlayersPlayingGroup variable is that, and gets reused).
I only want it to spawn units at player points where there are people playing.

Then verify to only run the next loop if the current wave is equal to the loop-integer. This to prevent it from spawning, say wave 20 units on round 12.

Then make sure it hasn't already spawned enough units, and as long as it hasn't reached that threshold, define the point, create the unit, destroy the point, and add 1 to the counter tracking number of units spawned.


Just looking at it I can see I'll have to rearrange where it resets the units spawned counter; lest an entire game full of 8 people only gets 3 units each to kill (currently outside of the trigger code block, thinking of putting it in one of the loops). And also where to (or whether to) include the "wait .25 seconds" at the end of the loop to make sure it doesn't spawn them all at once.

I'd really rather keep the wave spawning like this to one trigger (like this), instead of needing to spread it out thin amongst 50+ triggers that would essentially do the same thing, just take the more space.

weee for loops in loops in loops.

-- edit --
Also looking at it, I could probably simply take out the 'if then' checking the CurrentWaveSpawnCounter, since that's a number used in the group, and looped as many times as the MobsToSpawn[] integer is... wee.
 
Level 12
Joined
Apr 15, 2008
Messages
1,063
Mob Spawning
  • Spawn
    • Time - every 0.25 second of game time
  • Conditions
    • CurrentWaveSpawnCounter Less than MobsToSpawnPerWave[CurrentWaveIndex]
  • Actions
    • Player Group - Pick players in PlayingPlayersGrp
      • Set TempPoint = (Random point in PlayerSpawnRegions[(Player number of (Picked player))])
      • Unit - Create 1 Wave_UnitTypes[WaveSpawnIntegerA] for Player 9 (Gray) at TempPoint facing Default building facing degrees
      • Custom script: call RemoveLocation (udg_TempPoint)
    • Set CurrentWaveSpawnCounter = (CurrentWaveSpawnCounter + 1)
Next wave:
  • Events
    • Whatever activates new wave
  • Actions
    • set CurrentWaveIndex = CurrentWaveIndex + 1
    • Set CurrentWaveSpawnCounter = 0
 
Status
Not open for further replies.
Top