creating random waves (order)

MissKerrigan

Active Member
Reaction score
23
Hello,

- I got 9 towers in my tower defense

- marine
- stalker
- hydralisk
- marauder
- templar
- roach
- vulture
- immortal
- queen

Because of this, there are also 9 different wave tpyes (the same 9 units)
The marine shoots 75% damage to marine, the stalker 75% damage to stalker etc...
But that doesn't matter now


What I want to ask are 2 things

1. How do I create only the waves which are the available towers?

(in the start the players can only make marines - stalkers - hydralisks, so only this 3 units must appear as wave)


2. How do I create the waves randomly?

NOTE: if the first wave are the marines, then the next wave must be hydralisk or stalker, at last the wave which hasn't appeared yet must come, and after that the 3 wave types must come again randomly


(later in game when the player can build about 7 towers, there must come 7 different waves)

I tried to create a variable of an array size of 9 but I don't know how to create the units which are only available yet

Marloes
 

Dave312

Censored for your safe viewing
Reaction score
269
This is not very straight forward to do. You are on the right track by creating a variable array of size 9 (set the variable type to Unit Type). The best way to do this would be to create a custom function which returns the unit type for the wave. Create the following global variables:

- WaveUnits (variable type Unit Type, array of size 9)
- ArrayLength (variable type integer, set the default value to 0)

The WaveUnits variable is the variable you have already created. The ArrayLength variable just determines how many units are stored in the array. Once you have created these variables, create the following custom function (Ctrl+Alt+F):
Trigger:
  • GetRandomWaveUnit
    • Options: Function
    • Return Type: Game Link - Unit
    • Parameters
    • Grammar Text: GetRandomWaveUnit()
    • Hint Text: (None)
    • Custom Script Code
    • Local Variables
      • i = 0 <Integer>
      • Unit = No Game Link <Game Link - Unit>
      • UnitIndex = 0 <Integer>
    • Actions
      • ------- Check if there are no units in the array, if none add every available unit to the array
      • General - If (Conditions) then do (Actions) else do (Actions)
        • If
          • ArraySize == 0
        • Then
          • Variable - Set WaveUnits[0] = Marine
          • Variable - Set WaveUnits[1] = Stalker
          • Variable - Set WaveUnits[2] = Hydralisk
          • Variable - Set ArraySize = 3
          • ------- Check if Marauder is available
          • General - If (Conditions) then do (Actions) else do (Actions)
            • If
              • //Marauder Unit is Available
            • Then
              • Variable - Set WaveUnits[3] = Marauder
              • Variable - Modify ArraySize: + 1
            • Else
          • ------- Check if Templar is available
          • General - If (Conditions) then do (Actions) else do (Actions)
            • If
              • //Templar Unit is Available
            • Then
              • Variable - Set WaveUnits[4] = High Templar
              • Variable - Modify ArraySize: + 1
            • Else
          • ------- Check if the other units are available and add them to the array as per above
        • Else
      • ------- Select a random unit from the array
      • Variable - Set UnitIndex = (Random integer between 0 and (ArraySize - 1))
      • Variable - Set Unit = WaveUnits[UnitIndex]
      • ------- Remove selected unit from the array
      • General - For each integer i from UnitIndex to 8 with increment 1, do (Actions)
        • Actions
          • General - If (Conditions) then do (Actions) else do (Actions)
            • If
              • i < 8
            • Then
              • Variable - Set WaveUnits<i> = WaveUnits[(i + 1)]
            • Else
              • Variable - Set WaveUnits<i> = No Game Link
      • Variable - Modify ArraySize: - 1
    • </i></i>


Now when you want to work out what your next wave should be, just call this function:
Code:
Variable - Set NextWave = GetRandomWaveUnit()
 

MissKerrigan

Active Member
Reaction score
23
woow, I didn't expected this haha, it hurts my eyes when I analize it

would it easier if I create it like this?


- in start there are only 3 units available: marine stalker hydralisk
- so I create a trigger that brings a marine wave, then a stalker wave and at last a hydralisk wave
- the only thing I want to know how to add unlocked units to the wave-spawn-group
 

Dave312

Censored for your safe viewing
Reaction score
269
I suppose you could, but it wouldn't be random like you wanted and it would be the same amount of work if not more (your trigger would probably look much the same as the one I posted too).

I'm sure the trigger looks rather complicated, but really it isn't. And the concept of using functions is probably something you should learn if you want to create complex things. They can also make your triggers look much simpler and easier to read. I recommend you just try making it and if you get stuck, you can always ask for some help.
 

MissKerrigan

Active Member
Reaction score
23
I believe very well if you say the trigger is about the same size, I'm gonna read your post till I understand it haha THANKS
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top