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

Pick a random stored unit only once

Status
Not open for further replies.
Level 1
Joined
Jun 13, 2008
Messages
132
Hi, I'm creating a custom hero map and I have a problem with the creeps' system, I stored 40 units manually, CreepType[1]: Ghoul, CreepType[2]: Witch..., for example, and I need to create a random unit from that group, I use the TempInteger variable to select one, but then I want that kind of unit to be removed from the group so the same level does not repeat in stage 2 for example. Any idea on how to do it?
 
Level 7
Joined
Apr 17, 2017
Messages
316
The easiest thing that came to my mind was this:
  • Spawn
    • Events
      • Time - Every 2.00 seconds of game time
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • CreepType[Counter] Equal to No unit-type
        • Then - Actions
          • Set Counter = (Random integer number between 1 and 80)
          • Unit - Create 5 CreepType[Counter] for Player 1 (Red) at (Center of Region 000 <gen>) facing Default building facing degrees
          • Set CreepType[Counter] = No unit-type
        • Else - Actions
 

Chaosy

Tutorial Reviewer
Level 40
Joined
Jun 9, 2011
Messages
13,183
The easiest thing that came to my mind was this:
  • Spawn
    • Events
      • Time - Every 2.00 seconds of game time
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • CreepType[Counter] Equal to No unit-type
        • Then - Actions
          • Set Counter = (Random integer number between 1 and 80)
          • Unit - Create 5 CreepType[Counter] for Player 1 (Red) at (Center of Region 000 <gen>) facing Default building facing degrees
          • Set CreepType[Counter] = No unit-type
        • Else - Actions
Conceptually, this work. You need to put the if block in a loop though to make sure a unit type is spawned.

Even better solution is to:
rng = number between 1-80
create CreepType[rng] at...
set CreepType[rng] = CreepType[size (set to 80 at init)]
size = size - 1
 
Level 1
Joined
Jun 13, 2008
Messages
132
Conceptually, this work. You need to put the if block in a loop though to make sure a unit type is spawned.

Even better solution is to:
rng = number between 1-80
create CreepType[rng] at...
set CreepType[rng] = CreepType[size (set to 80 at init)]
size = size - 1

I did what you suggested but monsters are repeating as I spawn them. I want a monster to spawn only in stage one for example, then in stage two another kind of monster and in stage three another kind, and so on.
 
Level 1
Joined
Jun 13, 2008
Messages
132
Your trigger



Actions:
Set TempInteger = (Random integer number between 1 and IntegerMaxCreepType)
Unit - Create 1 CreepType[IntegerMaxCreepType] for Player 1 (red) at (Center of Región 036 <gen>) facing Vista edificio predeterminada degrees
Unidad - Order (Last created unit) to Move to (Center of Región 037 <gen>)
Set CreepType[TempInteger] = CreepType[IntegerMaxCreepType]
Set IntegerMaxCreepType = (IntegerMaxCreepType - 1)


The store trigger


If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Si: Condiciones
Entonces: Acciones
Set IntegerMaxCreepType = 40
Set CreepType[1] = Monster ( Mob )
Set CreepType[2] = Scorpión ( Mob )
Set CreepType[3] = Spider ( Mob )
Set CreepType[4] = Gnoll ( Mob )
Set CreepType[5] = Siren ( Mob )
Set CreepType[6] = Wisp ( Mob )
Set CreepType[7] = Murloc ( Mob )
Set CreepType[8] = Sátir ( Mob )
Set CreepType[9] = Giant Wing Beast ( Mob )
Set CreepType[10] = Wolf ( Mob )
Set CreepType[11] = Dark Troll ( Mob )
Set CreepType[12] = Treant ( Mob )
Set CreepType[13] = Necromancer ( Mob )
Set CreepType[14] = Centaur ( Mob )
Set CreepType[15] = Warrior Treant ( Mob )
Set CreepType[16] = Elemental ( Mob )
Set CreepType[17] = Marine Tortoise ( Mob )
Set CreepType[18] = Salamander ( Mob )
Set CreepType[19] = Steel Golem ( Mob )
Set CreepType[20] = Orc Ghost ( Mob )
Set CreepType[21] = Shadow ( Mob )
Set CreepType[22] = Banshee ( Mob )
Set CreepType[23] = Faceless ( Mob )
Set CreepType[24] = Necro Ant ( Mob )
Set CreepType[25] = Crustacean ( Mob )
Set CreepType[26] = Zombi ( Mob )
Set CreepType[27] = Ghoul ( Mob )
Set CreepType[28] = Goblin Machine ( Mob )
Set CreepType[29] = Ground Dragon ( Mob )
Set CreepType[30] = Harpy ( Mob )
Set CreepType[31] = Stone Golem ( Mob )
Set CreepType[32] = Small Demon ( Mob )
Set CreepType[33] = Catapult ( Mob )
Set CreepType[34] = Ogre ( Mob )
Set CreepType[35] = Alien ( Mob )
Set CreepType[36] = Wendigo ( Mob )
Set CreepType[37] = Quill Beast ( Mob )
Set CreepType[38] = Lava Demon ( Mob )
Set CreepType[39] = Spectral Banshee ( Mob )
Set CreepType[40] = Witch ( Mob )
Otros: Acciones
 
Level 1
Joined
Jun 13, 2008
Messages
132
The trigger you recently posted should work. Are you maybe using the variables IntegerMaxCreepType or TempInteger anywhere else?

Also, do note that if you care about the order in which you registered the units, then the method you're using is not ideal.
Order is not important, only important thing is to spawn the mobs only once, the 40 levels must have different enemies, and each time I restart the game, as the enemies get a different number, the stages will also be different.
 
Level 1
Joined
Jun 13, 2008
Messages
132
If order doesn't matter, than dynamic indexing should work. Would you be able to post all the triggers for your spawn system?

Since I'm experimenting, event is a periodic timer (2seconds):

Time - Every 2.00 seconds of game time


Actions
Set TempInteger = (Random integer number between 1 and IntegerMaxCreepType)
Unidad - Create 1 CreepType[TempInteger] for Player 1 (red) at (Center of Región 036 <gen>) facing Vista edificio predeterminada degrees
Unidad - Order (Last created unit) to Mover a (Center of Región 037 <gen>)
Set CreepType[TempInteger] = CreepType[IntegerMaxCreepType]
Set IntegerMaxCreepType = (IntegerMaxCreepType - 1)
 
Level 1
Joined
Jun 13, 2008
Messages
132
Actions:
Set IntegerCreepType = (Random integer number between 1 and IntegerMaxCreepType)
Unidad - Create 1 CreepType[IntegerCreepType] for Jugador 1 (rojo) at (Center of Región 036 <gen>) facing Vista edificio predeterminada degrees
Unidad - Order (Last created unit) to Mover a (Center of Región 037 <gen>)
Set CreepType[IntegerCreepType] = CreepType[IntegerMaxCreepType]
Set IntegerMaxCreepType = (IntegerMaxCreepType - 1)


I've changed the variable name so I only use it on this trigger but the problem remains.

Creeps repeat and at the end it starts to repeat a lot.
 
Status
Not open for further replies.
Top