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

Tower defence spawn trigger

Status
Not open for further replies.
Level 1
Joined
Jun 13, 2008
Messages
132
Hi there, I'm working on a tower defence and I need to spawn creeps at a certain order, to start with, creeps have to spawn from the range of 1 to 15 seconds and then from 30 to 45 seconds. I have made a multiboard and the seconds are stored as "IntegerSeconds".

Now, at second 1 or 30 I want to spawn CreepType1, at second 2 or 31, CreepType2, and so on up to second 15 or 45, where it is the end of the waves and I want to spawn the CreepType3.

For example, 1 second: spawn a crab, 2 second: spawn a turtle, 3 second: spawn a crab, 4 second: spawn a turtle, (...), 15 second: spawn a dog.

Can someone help me with this? I can't figure it out. Thanks in advance!
 
Level 5
Joined
Jul 27, 2017
Messages
73
Hi Mapas,
so i tried to make simple gui Trigger. I hope that it does what you want

  • Spawner
    • Ereignisse
      • Zeit - Countdowntimer expires
    • Bedingungen
    • Aktionen
      • For each (Integer A) from 1 to 15, do (Actions)
        • Schleifen - Aktionen
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • 'IF'-Bedingungen
              • ((Integer A) mod 2) Gleich 0
            • 'THEN'-Aktionen
              • Einheit - Create 1 Unittypes[0] for Spieler 1 (Rot) at SpawningPoint facing Vorgabe für Gebäude-Ausrichtung degrees
            • 'ELSE'-Aktionen
              • Einheit - Create 1 Unittypes[1] for Spieler 1 (Rot) at SpawningPoint facing Vorgabe für Gebäude-Ausrichtung degrees
          • Custom script: call DestroyGroup(bj_lastCreatedGroup)
          • Wait 1.00 seconds
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • 'IF'-Bedingungen
          • IsNotTheLastWave Gleich True
        • 'THEN'-Aktionen
          • -------- Set new Unittypes --------
          • Countdown-Timer - Start Countdowntimer as a Einmalig timer that will expire in 15.00 seconds
        • 'ELSE'-Aktionen
The idea is to create a trigger that triggers the spawning event (it is set again as a One-Time-Timer at the end of the trigger)
It uses the global variable Integer A to spawn 15 units and checks whether Integer A mod 2 equals 0.
After the creation it uses a custom script to remove the last created unit group (The GUI-Function creates a unit group and over time this will result in Lag of Doom if you do not remove them)
After that the trigger waits 1 second before the next spawn is executed.
After 15 units have been created the trigger checks if it is the last wave. If it is not the last wave you can set the new unittypes and restart the trigger.

I used a Unittype-Array to save the unittypes that stores 2 unittypes.

Other option (likely better): You create a longer array for unittypes and set them at the beginning and access the unittypes using the current wave.
Example: Unittypes[2*Currentwave] for unittype A and Unittypes[2*Currentwave+1]

If you prefer Jass then i can also offer this one
JASS:
function Trig_Spawner_Kopieren_Actions takes nothing returns nothing
    integer i = 0
    loop
        exitwhen i == 14
        if ( ModuloInteger(GetForLoopIndexA(), 2) == 0 ) ) then
            call CreateUnitAtLoc(Player(0), udg_Unittypes[0],  udg_SpawningPoint, bj_UNIT_FACING )
        else
            call CreateUnitAtLoc(Player(0), udg_Unittypes[1],  udg_SpawningPoint, bj_UNIT_FACING )
        endif
        call TriggerSleepAction( 1.00 )
        set i = i + 1
    endloop
    if ( udg_IsNotTheLastWave ) then
        // Set new Unittypes
        call StartTimerBJ( udg_Countdowntimer, false, 15.00 )
    endif
endfunction


I hope this helps.
PS: The better place to post this would be Triggers & Scripts
 
Level 5
Joined
Jul 27, 2017
Messages
73
I hoped that it would be clear. Ok i try to explain it again.

What i understood of what you want:
Second 1: Spawn a crab
Second 2: Spawn a turtle
Second 3: Spawn a crab
Second 4: Spawn a turtle
and so on until Second 15.

Now wait 15 seconds
Do that again with 2 different unittypes (e.g. dog and cat)

So the objective is to perform that spawn-action and then wait 15 seconds before it is done again.

What my suggestion was that:
There is a trigger that elapses after 15 seconds. Then there is a loop that does a spawn per second over a time of 15 seconds (Spawn something --> wait 1 second --> Spawn something --> wait 1 second --> ...)
There is an integer that counts the number of spawns (Integer A in the GUI-Version and the variable i in the jass code)

The spawning action in my triggers should work like that: if that integer can be devided by 2 (values would be: 2, 4, 6, 8, 10, 12, 14) then spawn a Unit of Type A else (values: 1, 3 , 5, 7, 9, 11, 13, 15) then spawn a unit from Type B

When that is done the Timer is restarted and will trigger this event again in 15 seconds. The if-clause is added to check if you have reached the final wave. (e.g. You have 20 waves and a variable CurrentWave it could be if(CurrentWave<20) )

About something that is likely confusing: Setting unittypes
You can initialize your unittypes like that:
  • Spawntest
    • Ereignisse
    • Bedingungen
    • Aktionen
      • Set Unittypes[0] = Crab
      • Set Unittypes[1] = Turtle
      • Set Unittypes[2] = Dog
      • Set Unittypes[3] = Cat
      • Set Unittypes[4] = Mouse
      • Set Unittypes[5] = Eagle
Then you can get unittype A using something like that (Assuming that the variable CurrentWave is at the beginning at 1)
Unittypes[CurrentWave*2-2] --> Values: 0, 2, 4
and the unittype B
Unittypes[CurrentWave*2-1] --> Values: 1, 3, 5


Other option: setting the variables after every wave which would look like that
  • SpawnTwo
    • Ereignisse
    • Bedingungen
    • Aktionen
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • 'IF'-Bedingungen
          • CurrentWave Gleich 2
        • 'THEN'-Aktionen
          • Set UnittypeA = Crab
          • Set UnittypeB = Turtle
        • 'ELSE'-Aktionen
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • 'IF'-Bedingungen
              • CurrentWave Gleich 3
            • 'THEN'-Aktionen
              • Set UnittypeA = Dog
              • Set UnittypeB = Cat
            • 'ELSE'-Aktionen
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • 'IF'-Bedingungen
                  • CurrentWave Gleich 4
                • 'THEN'-Aktionen
                  • Set UnittypeA = Mouse
                  • Set UnittypeB = Eagle
                • 'ELSE'-Aktionen
Ok while i see this: better use option 1 instead of this long If-Then-Else-Construction

Is it clearer or still just confusing?
 
Level 5
Joined
Jul 27, 2017
Messages
73
Hi,
i've added the trigger (and some others) to a map and tested it.
It spawns 2 unittypes per wave and a total of 15 units.

It worked so i think that you can adapt it to your map.
If it does not work please post you map so that we can look where the problem is.

Gauda
 

Attachments

  • TowerDefense.w3x
    22 KB · Views: 22
Level 1
Joined
Jun 13, 2008
Messages
132
I've seen your map, and it works, but then, I imported it to my map, and only one unit is spawned, nothing else happens.

To try it faster I've created the event player chats the text spawn to try it faster.

¿What could it be? @Gauda
 
Level 5
Joined
Jul 27, 2017
Messages
73
Hi Mapas,
maybe you could post your map so that we can take a look at it and have more information

Troubleshooting:
Are you setting your unittypes like i did in the map in the Initialization-Trigger? If the unittypes are setted this way the Spawn Trigger should work like that.

Are you using the global Integer A in other triggers too? If this is the case you can create an own global variable for this trigger or use jass to create a local one.

You can also make debug messages to post the value of the Integer A to see it's values. (Game - Display To (All players) the text: (String((Integer A))) )

Have you changed the trigger? If yes, then please post it so that we can take a look at it.

Have you also tested this without the player chat? If you only test it with the player chat it could mess things up when you still use the timer and enter something in the chat before the trigger finished.

These are some possible ideas but as i wrote there is more information required to find the error(s).

Gauda
 
Status
Not open for further replies.
Top