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

Streamlining Unit Spawn Trigger

Status
Not open for further replies.
Level 15
Joined
Feb 2, 2009
Messages
156
Hello friends, I am currently working on a spawn based RTS and I need a bit of help making an efficient spawn trigger for the units. Currently i'm using a 'for loop' to spawn multiple units in accordance to the amount of quarters (spawn amount upgrade), while issuing an order to each unit to move to the rally point of the spawn from the spawn point (Spawn Arthas Landing).

  • BoatSpawn
    • Events
    • Conditions
      • (Count non-structure units controlled by (Owner of Arthas' Ship 0008 <gen>) (Exclude incomplete units)) Less than UnitCap
      • (Arthas' Ship 0008 <gen> is alive) Equal to True
      • (Arthas' Ship 0008 <gen> has buff Inactive Spawn ) Equal to False
    • Actions
      • For each (Integer A) from 1 to (QuarterArthasLanding + 3), do (Actions)
        • Loop - Actions
          • Unit - Create 1 BasicUnitArray[(Player number of (Owner of Arthas' Ship 0008 <gen>))] for (Owner of Arthas' Landing 0057 <gen>) at (Center of Spawn Arthas Landing <gen>) facing Default building facing degrees
          • Unit - Order (Last created unit) to Move To (Rally-Point of Arthas' Ship 0008 <gen> as a point)
      • For each (Integer A) from 1 to (QuarterArthasLanding + 1), do (Actions)
        • Loop - Actions
          • Unit - Create 1 MageUnitArray[(Player number of (Owner of Arthas' Ship 0008 <gen>))] for (Owner of Arthas' Ship 0008 <gen>) at (Center of Spawn Arthas Landing <gen>) facing Default building facing degrees
          • Unit - Order (Last created unit) to Move To (Rally-Point of Arthas' Ship 0008 <gen> as a point)
          • Unit - Create 1 RangedUnitArray[(Player number of (Owner of Arthas' Ship 0008 <gen>))] for (Owner of Arthas' Ship 0008 <gen>) at (Center of Spawn Arthas Landing <gen>) facing Default building facing degrees
          • Unit - Order (Last created unit) to Move To (Rally-Point of Arthas' Ship 0008 <gen> as a point)
          • Unit - Create 1 MageUnitArray[(Player number of (Owner of Arthas' Ship 0008 <gen>))] for (Owner of Arthas' Ship 0008 <gen>) at (Center of Spawn Arthas Landing <gen>) facing Default building facing degrees
          • Unit - Order (Last created unit) to Move To (Rally-Point of Arthas' Ship 0008 <gen> as a point)
My problem is this; I have a multitude of these spawn triggers in the map and they all trigger on the same periodic timer. I need to add many more so for the sake of time is there some way to store the player who owns each spawn at the start of the variable, but in a way that will allow these triggers to run at the same time? I considered just using a basic player variable labeled 'owner', and then using the Wait function between each spawn trigger in the periodic trigger to allow each one to run without problems but I get the feeling there could be a more graceful solution.

Any help would be greatly appreciated!
 
Level 39
Joined
Feb 27, 2007
Messages
5,013
Some things you should know:
  • (Rally-Point of Arthas' Ship 0008 <gen> as a point) leaks a point which will end up slowing down your map over time.
  • (Center of Spawn Arthas Landing <gen>) also leaks a point. You leak these same two points multiple times per loop, so it will matter.
Now your intuition about using variables is correct: you'll need a unit array to store all of the spawn buildings, a point array to store the spawn locations, and an integer array to store the number of quarters at each location. I would also recommend a TempPlayer and TempInt variable to store things like Owner of... that you will use multiple times. The first two of these will be set on map initialization; if units like Arthas' Ship 0008 can be killed permanently then you will also need to re-assign an index of the unit array to the new unit when it's spawned for the new owner.

  • Events
    • Map Initialization
  • Conditions
  • Actions
    • Set SpawnCounter = SpawnCounter + 1
    • Set SpawnUnit[SpawnCounter] = Arthas' Ship 0008 <gen>
    • Set SpawnPoint[SpawnCounter] = Center of Spawn Arthas Landing <gen>
    • -------- --------
    • Set SpawnCounter = SpawnCounter + 1
    • Set SpawnUnit[SpawnCounter] = Arthas' Hot Air Balloon 0002 <gen>
    • Set SpawnPoint[SpawnCounter] = Center of Spawn Arthas Airfield <gen>
    • -------- --------
    • Set SpawnCounter = SpawnCounter + 1
    • Set SpawnUnit[SpawnCounter] = Grom's Birthday Party 0001 <gen>
    • Set SpawnPoint[SpawnCounter] = Center of Spawn Grom House <gen>
    • -------- --------
    • etc. for all spawn location/unit combos
  • Events
    • Time - Every N seconds of game-time
  • Conditions
  • Actions
    • For each (Integer A) from 1 to SpawnCounter do (Actions)
      • Loop - Actions
        • Set TempPlayer = (Owner of SpawnUnit[(Integer A)])
        • Set TempInt = (Player number of TempPlayer)
        • If (All conditions are true) then do (Then actions) else do (Else actions)
          • If - Conditions
            • (Count non-structure units controlled by TempPlayer (Exclude incomplete units)) Less than UnitCap
            • (SpawnUnit[(Integer A)] is alive) Equal to True
            • (SpawnUnit[(Integer A)] has buff Inactive Spawn) Equal to False
          • Then - Actions
            • Set TempPoint = (Rally-Point of SpawnUnit[(Integer A)] as a point)
            • For each (Integer A) from 1 to SpawnQuarters[(Integer A)] + 3 do (Actions)
              • Loop - Actions
                • Unit - Create 1 BasicUnitArray[TempInt] for TempPlayer at SpawnPoint[(Integer A)] facing Default building facing degrees
                • Unit - Order (last created unit) to Move to TempPoint
            • For each (Integer A) from 1 to SpawnQuarters[(Integer A)] + 1 do (Actions)
              • Loop - Actions
                • Unit - Create 1 MageUnitArray[TempInt] for TempPlayer at SpawnPoint[(Integer A)] facing Default building facing degrees
                • Unit - Order (last created unit) to Move to TempPoint
                • Unit - Create 1 RangedUnitArray[TempInt] for TempPlayer at SpawnPoint[(Integer A)] facing Default building facing degrees
                • Unit - Order (last created unit) to Move to TempPoint
                • Unit - Create 1 MageUnitArray[TempInt] for TempPlayer at SpawnPoint[(Integer A)] facing Default building facing degrees
                • Unit - Order (last created unit) to Move to TempPoint
            • Custom script: call RemoveLocation(udg_TempPoint) //change the name here to match the name of your temporary point variable set above, but keep the udg_ prefix; this cleans the point leak
          • Else - Actions
You will finally need some way to update the SpawnQuarters[] variables when new quarters are built. Without knowing how you have already done that it's hard to suggest but you can probably do something like this:

  • Set TempUnit = <the spawn unit for the area the quarters was built in, however you get that; probably regions build events?>
  • For each (Integer A) from 1 to SpawnCounter do (Actions)
    • Loop - Actions
      • If (All conditions are true) then do (Then actions) else do (Else actions)
        • If - Conditions
          • TempUnit equal to SpawnUnit[(Integer A)]
        • Then - Actions
          • Set SpawnQuarters[(Integer A)] = SpawnQuarters[(Integer A)] + 1
        • Else - Actions
 
Status
Not open for further replies.
Top