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

Easier Spawning For TD

Status
Not open for further replies.
Level 4
Joined
Feb 28, 2009
Messages
73
So for my TD im having to spawn all my units by:

  • Lvl 1
    • Events
      • Time - LvlTimer expires
    • Conditions
    • Actions
      • Game - Display to (All players) the text: |cff7777aaLevel|r 1...
      • Set loc = (Center of Red Start <gen>)
      • Unit - Create 1 Lvl 1 for Player 7 (Green) at loc facing Default building facing degrees
      • Custom script: call RemoveLocation(udg_loc)
      • Set loc = (Center of Blue Start <gen>)
      • Unit - Create 1 Lvl 1 for Player 7 (Green) at loc facing Default building facing degrees
      • Custom script: call RemoveLocation(udg_loc)
      • Set loc = (Center of Teal Start <gen>)
      • Unit - Create 1 Lvl 1 for Player 7 (Green) at loc facing Default building facing degrees
      • Custom script: call RemoveLocation(udg_loc)
      • Set loc = (Center of Purple Start <gen>)
      • Unit - Create 1 Lvl 1 for Player 7 (Green) at loc facing Default building facing degrees
      • Custom script: call RemoveLocation(udg_loc)
      • Set loc = (Center of Yellow Start <gen>)
      • Unit - Create 1 Lvl 1 for Player 7 (Green) at loc facing Default building facing degrees
      • Custom script: call RemoveLocation(udg_loc)
      • Set loc = (Center of Orange Start <gen>)
      • Unit - Create 1 Lvl 1 for Player 7 (Green) at loc facing Default building facing degrees
      • Custom script: call RemoveLocation(udg_loc)
      • Wait 0.25 seconds
      • //(Then that 9 more times for 10 units at 6 places.)
      • Trigger - Turn on Lvl 2 <gen>
      • Wait 0.01 seconds
      • Trigger - Turn off (This trigger)
Is there any easier way to make it spawn each level, 10 units each, except bosses. Like a variable that increases, if it equals "x" then spawn "x" units in "x" locations?
 
Level 20
Joined
Jul 6, 2009
Messages
1,885
Use
  • For each (Integer A) from 1 to 10, do (Actions)
    • Loop - Actions
      • Set TempPoint = ((Player((Integer A))) start location)
      • Unit - Create 1 Lvl 1 for Player 7 (Green) at TempPoint facing Default building facing degrees
      • Custom script: call RemoveLocation(udg_TempPoint)
 
Level 20
Joined
Jul 6, 2009
Messages
1,885
You can set it to region. Create a region array variable and at initialization trigger set it like this:
  • Init
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set RegionArray[1] = Region 000 <gen>
      • Set RegionArray[2] = Region 001 <gen>
      • Set RegionArray[3] = Region 002 <gen>
      • Set RegionArray[4] = Region 003 <gen>
RegionArray[1] should be region that is for player red,region 2 for blue etc...
And use:
  • For each (Integer A) from 1 to 10, do (Actions)
    • Loop - Actions
      • Set TempPoint = (Center of RegionArray[(Integer A)])
      • Unit - Create 1 Lvl 1 for Player 7 (Green) at TempPoint facing Default building facing degrees
      • Custom script: call RemoveLocation(udg_TempPoint)
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,202
Garfield1337, you never wrote a function. You wrote a piece of code.

This will not reduce any lag at all. Lag is usually caused by poor connections or too may net traffic actions, find the cause of the lag and then work on a solution. If you mean reduced framerate, it will only reduce the frame rate further acording to logic as it is now doing a loop however this should not be causing any framerate reduction as it is hardly an intesnive opperation (leaving windows live messanger open in the background will eat up more time). Any low framerate must be from some other cause.

Alright. Can i just put a "Wait .25 secs" Then copy the action 10 times? i wanna spawn 10 units at each place. .25 seconds apart
No as the wait function in WC3 (TriggerSleepAction) is not very accurate and so is always longer than the specified time. Infact in multiplayer it gets even worse reaching nearly twice as long as the time specified with no real constant multiple.

I advise using a timer to time the spawns as those are always accurate to a high degree. Just run a function with that code in it every time the timer expires and set the timer to perodic mode with a timeout of 0.25 seconds. Use a global integer to keep track of the number spawned and turn the timer off/destroy the timer when 10 units are spawned.
 
Level 20
Joined
Jul 6, 2009
Messages
1,885
@DSG
Well,i said that even if it does reduce lag,it would be tiny,but i thought it probably wouldn't. And yes,you're right that i've mistaken lag for framerate.

@Clawdruid
  • StartSpawn
    • Events
    • //When you want your units to spawn
    • Conditions
    • Actions
      • Set IntegerVar = 0
      • Countdown Timer - Start TimerVar as a Repeating timer that will expire in 0.25 seconds
  • Spawn
    • Events
      • Time - TimerVar expires
    • Conditions
    • Actions
      • Set IntegerVar = (IntegerVar + 1)
      • For each (Integer A) from 1 to 10, do (Actions)
        • Loop - Actions
          • Set TempPoint = (Center of RegionArray[(Integer A)])
          • Unit - Create 1 Footman for Player 7 (Green) at TempPoint facing Default building facing degrees
          • Custom script: call RemoveLocation(udg_TempPoint)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • IntegerVar Equal to 10
        • Then - Actions
          • Countdown Timer - Pause TimerVar
        • Else - Actions
 
Level 20
Joined
Jul 6, 2009
Messages
1,885
This one is leakless
  • WaveEnd
    • Events
      • Unit - A unit Dies
    • Conditions
    • Actions
      • Set GroupVar = (Units in (Playable map area) matching ((Unit-type of (Matching unit)) Equal to Footman))
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Number of units in GroupVar) Equal to 0
        • Then - Actions
          • Trigger - Run StartSpawn <gen> (ignoring conditions)
        • Else - Actions
      • Custom script: call DestroyGroup(udg_GroupVar)
 
Status
Not open for further replies.
Top