• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Random towers for builder?

Level 1
Joined
Apr 14, 2025
Messages
1
I was wondering if it was possible that a builder does't just have the same towers, but if it could be coded that the builder would receive a couple of towers randomly.
So if there were basic, normal and advanced towers:

A B C D E (Basic)
F G H I J (Normal)
K L M N O (Advanced)

He could get something like this as his "structures built":

B D E
F I J
K M O
 

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,917
So you can't edit Hotkeys at runtime so unless you rely on a completely alternate mechanic (custom UI) or an insane amount of Object Editor data (copies of each unit) then that's not going to happen.

But if that's a compromise you're willing to make then you can simply add every single tower to your builder's "Structures Built" field, disable their availability using triggers, and then randomly enable some of them using triggers. You can hold shift while opening the "Structures Built" field to bypass the build cap.

Here's a working system you could use. This trigger is where you set everything up and get the system up and running:
  • RT Setup
    • Events
      • Time - Elapsed game time is 0.01 seconds
    • Conditions
    • Actions
      • -------- =============================================================== --------
      • -------- DEFINE how many different types of towers you have - remember to update this: --------
      • Set VariableSet Random_Tower_Count = 6
      • -------- --------
      • -------- DEFINE your different types of towers: --------
      • Set VariableSet Random_Tower_Type[1] = Guard Tower
      • Set VariableSet Random_Tower_Type[2] = Cannon Tower
      • Set VariableSet Random_Tower_Type[3] = Arcane Tower
      • Set VariableSet Random_Tower_Type[4] = Sky-Fury Tower
      • Set VariableSet Random_Tower_Type[5] = Dalaran Guard Tower
      • Set VariableSet Random_Tower_Type[6] = Death Tower
      • -------- * Copy and paste the above variable and add more tower types as needed... --------
      • -------- =============================================================== --------
      • -------- --------
      • -------- Note: You don't have to edit anything else from this point on. Only do so if you know what you're doing! --------
      • -------- --------
      • -------- Create, hide, and track the towers. This acts like your "hat" that you can use to "draw a random name from the hat" later on: --------
      • For each (Integer Random_Tower_Loop) from 1 to Random_Tower_Count, do (Actions)
        • Loop - Actions
          • Unit - Create 1 Random_Tower_Type[Random_Tower_Loop] for Neutral Passive at (Center of OutOfSight <gen>) facing Default building facing degrees
          • Unit - Hide (Last created unit)
          • Unit Group - Add (Last created unit) to Random_Tower_Base_Group
      • -------- --------
      • -------- Disable construction of ALL random towers for each player: --------
      • Player Group - Pick every player in (All players) and do (Actions)
        • Loop - Actions
          • For each (Integer Random_Tower_Loop) from 1 to Random_Tower_Count, do (Actions)
            • Loop - Actions
              • Player - Make Random_Tower_Type[Random_Tower_Loop] Unavailable for training/construction by (Picked player)
^ You need to define the variables between the ===== comments I've made and you need to edit the "Unit - Create" action to use your own Region:
  • (Center of OutOfSight <gen>)
I created this Region in the corner of my map, away from anything important. I recommend doing the same thing.

Then here's how you can enable some random towers for a player:
  • RT Enable Random Towers
    • Events
      • Player - Player 1 (Red) types a chat message containing go as An exact match
      • Player - Player 2 (Blue) types a chat message containing go as An exact match
      • Player - Player 3 (Teal) types a chat message containing go as An exact match
    • Conditions
    • Actions
      • -------- Fill up your "hat" with random "tower names" that you can then pull from: --------
      • Unit Group - Remove all units from Random_Tower_RNG_Group.
      • Unit Group - Add all units of Random_Tower_Base_Group to Random_Tower_RNG_Group
      • -------- --------
      • -------- [OPTIONAL] Disable all of the player's current towers before getting new ones: --------
      • For each (Integer Random_Tower_Loop) from 1 to Random_Tower_Count, do (Actions)
        • Loop - Actions
          • Player - Make Random_Tower_Type[Random_Tower_Loop] Unavailable for training/construction by (Triggering player)
      • -------- --------
      • -------- Enable construction of 'X' random towers for the desired player. X is 3 in this example: --------
      • For each (Integer Random_Tower_Loop) from 1 to 3, do (Actions)
        • Loop - Actions
          • Set VariableSet Random_Tower = (Random unit from Random_Tower_RNG_Group)
          • Unit Group - Remove Random_Tower from Random_Tower_RNG_Group.
          • Player - Make (Unit-type of Random_Tower) Available for training/construction by (Triggering player)
^ This trigger shows you HOW to enable the towers randomly, but you'll obviously want to customize the logic to suit the needs of your map. For example, you may want to pick every player at the 60.00 second mark and enable the random towers for them then. To do this, the Actions would remain mostly the same, aside from some Event Responses changing like (Triggering player) becoming (Picked player).

Your builder MUST be able to build every single one of these towers for the system to work:
1747830618862.png


To test the map:
Once in-game, type "go" and you'll be given 3 random towers from the 6 different types that I've defined in the RT Setup trigger.
 

Attachments

  • Random Towers 1.w3m
    19.6 KB · Views: 3
Last edited:
Level 14
Joined
Jan 10, 2023
Messages
261
Building off of what Uncle suggested I made a similar system (rain kept me in today lol).

I modified it to make it a bit more modular since you mentioned having basic, normal, and advanced towers, I think when Uncle said you won't get exactly what you want, that was in reference to having multiple build menus, but assuming that you don't care about that, you could at least have them all neatly placed into rows on a single build menu if you set all basic tower command button coordinates to (0,0), then all normal towers to (0,1), and advanced towers to (0,2) - at least in my testing, they always move to the right when displaced before moving up or down.

So if you had 4 basic, 3 normal, and 2 advanced towers you could have a command card that looks like this with little effort:
[1] [1] [1] [1]
[2] [2] [2] [ ]
[3] [3] [ ] [x]



I tried to keep close to Uncle's concept, but made some changes where it made sense to since I was trying to make you an example that could easily allow for more tech-levels.

Three basic steps to enable/disable a set of random towers for a player:
  1. Define a Tower Group (my example uses groups named A/B/C for basic/normal/advanced)
  2. Set player variable Random_Tower_Player to the target player (added to allow a bit more control)
  3. Run trigger actions to either enable a random set of towers from the defined Tower Group for Random_Tower_Player
    • OR disable the defined Tower Group for Random_Tower_Player
Variables:
Player Random_Tower_Player
Unit-Type array Random_Tower_Type[]
Integer Random_Tower_Count
Integer Random_Tower_Limit
Integer Random_Tower_Loop
Integer Random_Tower_RN


  • RT Define Tower Group A
    • Events
    • Conditions
    • Actions
      • -------- =============================================================== --------
      • -------- DEFINE how many different types of towers you have and the max types allowed of each tower rank - remember to update this: --------
      • -------- --------
      • Set VariableSet Random_Tower_Count = 8
      • Set VariableSet Random_Tower_Limit = 4
      • -------- --------
      • -------- --------
      • -------- DEFINE your different types of towers: --------
      • -------- --------
      • Set VariableSet Random_Tower_Type[1] = Guard Tower
      • Set VariableSet Random_Tower_Type[2] = Cannon Tower
      • Set VariableSet Random_Tower_Type[3] = Arcane Tower
      • Set VariableSet Random_Tower_Type[4] = Flame Tower
      • Set VariableSet Random_Tower_Type[5] = Energy Tower
      • Set VariableSet Random_Tower_Type[6] = Death Tower
      • Set VariableSet Random_Tower_Type[7] = Cold Tower
      • Set VariableSet Random_Tower_Type[8] = Boulder Tower
      • -------- --------
      • -------- * Copy and paste the above variable and add more tower types as needed... --------
  • RT Define Tower Group B
    • Events
    • Conditions
    • Actions
      • -------- =============================================================== --------
      • -------- DEFINE how many different types of towers you have and the max types allowed of each tower rank - remember to update this: --------
      • -------- --------
      • Set VariableSet Random_Tower_Count = 5
      • Set VariableSet Random_Tower_Limit = 3
      • -------- --------
      • -------- --------
      • -------- DEFINE your different types of towers: --------
      • -------- --------
      • Set VariableSet Random_Tower_Type[1] = Advanced Flame Tower
      • Set VariableSet Random_Tower_Type[2] = Advanced Energy Tower
      • Set VariableSet Random_Tower_Type[3] = Advanced Death Tower
      • Set VariableSet Random_Tower_Type[4] = Advanced Cold Tower
      • Set VariableSet Random_Tower_Type[5] = Advanced Boulder Tower
      • -------- --------
      • -------- * Copy and paste the above variable and add more tower types as needed... --------
  • RT Define Tower Group C
    • Events
    • Conditions
    • Actions
      • -------- =============================================================== --------
      • -------- DEFINE how many different types of towers you have and the max types allowed of each tower rank - remember to update this: --------
      • -------- --------
      • Set VariableSet Random_Tower_Count = 3
      • Set VariableSet Random_Tower_Limit = 2
      • -------- --------
      • -------- --------
      • -------- DEFINE your different types of towers: --------
      • -------- --------
      • Set VariableSet Random_Tower_Type[1] = Sky-Fury Tower
      • Set VariableSet Random_Tower_Type[2] = Earth-Fury Tower
      • Set VariableSet Random_Tower_Type[3] = High Elven Guard Tower
      • -------- --------
      • -------- * Copy and paste the above variable and add more tower types as needed... --------
  • RT Disable Player RT Group
    • Events
    • Conditions
    • Actions
      • -------- Always define Random_Tower_Player and define a Tower Group before calling this (see trigger "RT Define Tower A" for Tower Group example). --------
      • -------- =============================================================== --------
      • -------- Disables construction of towers in the defined Tower Group for Random_Tower_Player --------
      • -------- --------
      • For each (Integer Random_Tower_Loop) from 1 to Random_Tower_Count, do (Actions)
        • Loop - Actions
          • Player - Make Random_Tower_Type[Random_Tower_Loop] Unavailable for training/construction by Random_Tower_Player
  • RT Disable Player RT Group
    • Events
    • Conditions
    • Actions
      • -------- Always define Random_Tower_Player and define a Tower Group before calling this (see trigger "RT Define Tower A" for Tower Group example). --------
      • -------- =============================================================== --------
      • -------- Disables construction of towers in the defined Tower Group for Random_Tower_Player --------
      • -------- --------
      • For each (Integer Random_Tower_Loop) from 1 to Random_Tower_Count, do (Actions)
        • Loop - Actions
          • Player - Make Random_Tower_Type[Random_Tower_Loop] Unavailable for training/construction by Random_Tower_Player
  • Init
    • Events
      • Time - Elapsed game time is 0.01 seconds
    • Conditions
    • Actions
      • -------- =============================================================== --------
      • -------- Run a "Define Tower" trigger action to recall that tower group to memory. --------
      • -------- --------
      • Trigger - Run RT Define Tower Group A <gen> (checking conditions)
      • Player Group - Pick every player in (All players) and do (Actions)
        • Loop - Actions
          • -------- =============================================================== --------
          • -------- Set Random_Tower_Player to the target Player to enable/disable towers for. --------
          • -------- --------
          • Set VariableSet Random_Tower_Player = (Picked player)
          • -------- =============================================================== --------
          • -------- Run "RT Disable Player RT Group" to disable all towers from that Tower Group for Random_Tower_Player --------
          • -------- --------
          • Trigger - Run RT Disable Player RT Group <gen> (checking conditions)
      • -------- =============================================================== --------
      • -------- Repeat above for all tower groups. --------
      • -------- --------
      • Trigger - Run RT Define Tower Group B <gen> (checking conditions)
      • Player Group - Pick every player in (All players) and do (Actions)
        • Loop - Actions
          • Set VariableSet Random_Tower_Player = (Picked player)
          • Trigger - Run RT Disable Player RT Group <gen> (checking conditions)
      • Trigger - Run RT Define Tower Group C <gen> (checking conditions)
      • Player Group - Pick every player in (All players) and do (Actions)
        • Loop - Actions
          • Set VariableSet Random_Tower_Player = (Picked player)
          • Trigger - Run RT Disable Player RT Group <gen> (checking conditions)
  • Randomize Basic RT Group
    • Events
      • Player - Player 1 (Red) types a chat message containing randomize basic as An exact match
    • Conditions
    • Actions
      • Trigger - Run RT Define Tower Group A <gen> (checking conditions)
      • Player Group - Pick every player in (All players) and do (Actions)
        • Loop - Actions
          • Set VariableSet Random_Tower_Player = (Picked player)
          • Trigger - Run RT Enable Player RT Group <gen> (checking conditions)
  • Randomize Normal RT Group
    • Events
      • Player - Player 1 (Red) types a chat message containing randomize normal as An exact match
    • Conditions
    • Actions
      • Trigger - Run RT Define Tower Group B <gen> (checking conditions)
      • Player Group - Pick every player in (All players) and do (Actions)
        • Loop - Actions
          • Set VariableSet Random_Tower_Player = (Picked player)
          • Trigger - Run RT Enable Player RT Group <gen> (checking conditions)
  • Randomize Advanced RT Group
    • Events
      • Player - Player 1 (Red) types a chat message containing randomize advanced as An exact match
    • Conditions
    • Actions
      • Trigger - Run RT Define Tower Group C <gen> (checking conditions)
      • Player Group - Pick every player in (All players) and do (Actions)
        • Loop - Actions
          • Set VariableSet Random_Tower_Player = (Picked player)
          • Trigger - Run RT Enable Player RT Group <gen> (checking conditions)
  • Randomize All
    • Events
      • Player - Player 1 (Red) types a chat message containing randomize all as An exact match
    • Conditions
    • Actions
      • Trigger - Run Randomize Basic RT Group <gen> (checking conditions)
      • Trigger - Run Randomize Normal RT Group <gen> (checking conditions)
      • Trigger - Run Randomize Advanced RT Group <gen> (checking conditions)
  • Disable Basic RT Group
    • Events
      • Player - Player 1 (Red) types a chat message containing disable basic as An exact match
    • Conditions
    • Actions
      • Trigger - Run RT Define Tower Group A <gen> (checking conditions)
      • Player Group - Pick every player in (All players) and do (Actions)
        • Loop - Actions
          • Set VariableSet Random_Tower_Player = (Picked player)
          • Trigger - Run RT Disable Player RT Group <gen> (checking conditions)
  • Disable Normal RT Group
    • Events
      • Player - Player 1 (Red) types a chat message containing disable normal as An exact match
    • Conditions
    • Actions
      • Trigger - Run RT Define Tower Group B <gen> (checking conditions)
      • Player Group - Pick every player in (All players) and do (Actions)
        • Loop - Actions
          • Set VariableSet Random_Tower_Player = (Picked player)
          • Trigger - Run RT Disable Player RT Group <gen> (checking conditions)
  • Disable Advanced RT Group
    • Events
      • Player - Player 1 (Red) types a chat message containing disable advanced as An exact match
    • Conditions
    • Actions
      • Trigger - Run RT Define Tower Group C <gen> (checking conditions)
      • Player Group - Pick every player in (All players) and do (Actions)
        • Loop - Actions
          • Set VariableSet Random_Tower_Player = (Picked player)
          • Trigger - Run RT Disable Player RT Group <gen> (checking conditions)
  • Disable All (does the same at Init)
    • Events
      • Player - Player 1 (Red) types a chat message containing disable all as An exact match
      • Time - Elapsed game time is 0.01 seconds
    • Conditions
    • Actions
      • Trigger - Run Disable Basic RT Group <gen> (checking conditions)
      • Trigger - Run Disable Normal RT Group <gen> (checking conditions)
      • Trigger - Run Disable Advanced RT Group <gen> (checking conditions)
 

Attachments

  • Random Towers 1.1.w3m
    24.2 KB · Views: 0
Last edited:
Top