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

Is there a more efficient way of doing this?

Status
Not open for further replies.
Level 8
Joined
Jul 29, 2010
Messages
319
Just wondering if there is a more efficient way of doing this, the goal of the trigger is to index all units that will be used in my map as potential enemies and allocate a series of variables. Example being that the variables being used for the "Crawler" are indexed 1 to 20, the crawler is saved under "mutants" with the index of "INTEGER" which constantly increases by 1 per allocation, so this, in turn, creates 20 potential variables for the Crawler unit.
  • Index
    • Events
      • Time - Elapsed game time is 0.05 seconds
    • Conditions
    • Actions
      • For each (Integer A) from 1 to 20, do (Actions)
        • Loop - Actions
          • Set INTEGER = (INTEGER + 1)
          • Set Mutants[INTEGER] = Crawler
          • Game - Display to (All players) the text: (String(INTEGER))
      • For each (Integer A) from 1 to 40, do (Actions)
        • Loop - Actions
          • Set INTEGER = (INTEGER + 1)
          • Set Mutants[INTEGER] = Cyst
          • Game - Display to (All players) the text: (String(INTEGER))
      • For each (Integer A) from 1 to 20, do (Actions)
        • Loop - Actions
          • Set INTEGER = (INTEGER + 1)
          • Set Mutants[INTEGER] = Slasher
          • Game - Display to (All players) the text: (String(INTEGER))
      • For each (Integer A) from 1 to 5, do (Actions)
        • Loop - Actions
          • Set INTEGER = (INTEGER + 1)
          • Set Mutants[INTEGER] = Husk
          • Game - Display to (All players) the text: (String(INTEGER))
      • For each (Integer A) from 1 to 5, do (Actions)
        • Loop - Actions
          • Set INTEGER = (INTEGER + 1)
          • Set Mutants[INTEGER] = Skrake
          • Game - Display to (All players) the text: (String(INTEGER))
Once these variables are assigned to their units they will then be used for this trigger. Which will generate a random number between 1 and 80, the purpose of there being so many variables for one unit is so that I'm able to control the likelihood of that unit being spawned, If any number between 1 to 20 will spawn a crawler then there is a 16% chance of that unit being spawned each time the trigger is run.
  • Spawning
    • Events
      • Time - SpawnTimer expires
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Number of units in Current_Wave) Less than 30
        • Then - Actions
          • Set UnitType = (Random integer number between 1 and 80)
          • Unit - Create 1 Mutants[UnitType] for Player 10 (Light Blue) at (Center of REGIONS[(Random integer number between 1 and 8)]) facing Default building facing degrees
          • Unit Group - Add all units of (Last created unit group) to Current_Wave
          • Unit Group - Pick every unit in Current_Wave and do (Actions)
            • Loop - Actions
              • Unit - Order (Picked unit) to Attack Arcane Summoner 0012 <gen>
          • Countdown Timer - Start SpawnTimer as a One-shot timer that will expire in 0.50 seconds
        • Else - Actions
I wasn't aware of any other method that would allow me to specify that I wanted any number between 1 and 20 to represent that particular unit. Any help or advice is greatly appreciated guys :D
 
Level 7
Joined
Dec 28, 2014
Messages
83
For my version, I am using a similar method of how item drops works in Melee maps.

You can easily change the chance of the unit type:

  • Round 1
    • Events
    • Conditions
    • Actions
      • Game - Display to (All players) the text: Humans
      • Set Enemies[1] = Footman
      • Set EnemiesChance[1] = 35
      • Set Enemies[2] = Rifleman
      • Set EnemiesChance[2] = 15
      • Set Enemies[3] = Priest
      • Set EnemiesChance[3] = 25
      • Set Enemies[4] = Spell Breaker
      • Set EnemiesChance[4] = 15
      • Set Enemies[5] = Knight
      • Set EnemiesChance[5] = 10
      • Set EnemyTypeCount = 6
But it is slow when choosing what type of unit to create:

  • Spawning
    • Events
      • Time - Every 0.50 seconds of game time
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Number of units in CurrentWave) Less than 30
        • Then - Actions
          • Trigger - Run GetEnemyType <gen> (ignoring conditions)
          • Unit - Create 1 Enemies[UnitType] for Player 1 (Red) at (Center of (Playable map area)) facing Default building facing degrees
          • Unit Group - Add all units of (Last created unit group) to CurrentWave
        • Else - Actions
This works exactly like the Jass function RandomDistChoose (but slower since it is GUI), but for units:

  • GetEnemyType
    • Events
    • Conditions
    • Actions
      • Set Sum = 0
      • -------- No units? --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • EnemyTypeCount Equal to 0
        • Then - Actions
          • Set UnitType = -1
          • Skip remaining actions
        • Else - Actions
      • -------- Find sum of all chances --------
      • For each (Integer A) from 1 to EnemyTypeCount, do (Actions)
        • Loop - Actions
          • Set Sum = (Sum + EnemiesChance[(Integer A)])
      • -------- Choose random number within the total range --------
      • Set Chance = (Random integer number between 1 and Sum)
      • -------- Find ID which corresponds to this chance --------
      • Set Sum = 0
      • Set Index = 0
      • For each (Integer Done) from 0 to 2, do (Actions)
        • Loop - Actions
          • -------- Repeats the loop until the condition is met --------
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Done Greater than 0
            • Then - Actions
              • Set Done = 0
            • Else - Actions
          • Set Sum = (Sum + EnemiesChance[Index])
          • -------- Check 1 --------
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Chance Less than or equal to Sum
            • Then - Actions
              • Set UnitType = Index
              • Set Done = 2
            • Else - Actions
          • Set Index = (Index + 1)
          • -------- Check 2 --------
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Index Equal to EnemyTypeCount
            • Then - Actions
              • Set Done = 2
            • Else - Actions
This version initializes faster, easier to change the chances, but slow when spawning units.

I added a sample map in the attachment.
 

Attachments

  • Random Spawn.w3x
    20.3 KB · Views: 20
Last edited:
Status
Not open for further replies.
Top