• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

[General] I have 200 towers, but I would like my builder to be able to randomly pick 8 or 9 towers from those 200.How to do it??

Level 2
Joined
Feb 8, 2020
Messages
3
Hi everybody. I asked this question many years ago and can't find any reference to it.
So lets just say I have 66 low-grade towers, 66 mid-grade towers, and 66 high-end towers. I would like to have it so when a certain race is picked(Let's call it "mixed tower race"), that 3 towers from each grade would be buildable for this race.(So 3 low-end, 3 mid, and 3 high-end towers). This is something I've been wanting to add this feature to my map for YEARS but never got around to it. I would actually like to make a version of the map that has ONLY this race. Now that I'd like to try I'm actually a little lost in WE. LOL.
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,583
Hello, what you want to do is create a Unit-Type Array variable to store all of your buildings.

You set these variables at the start of the game:
  • Events
    • Time - Elapsed game time is 0.00 seconds
  • Conditions
  • Actions
    • Set Variable Tower_Type[1] = Guard Tower
    • Set Variable Tower_Type[2] = Arcane Tower
    • // repeat this process for all 200 towers
Then you can reference them at random by "rolling the dice":
  • Actions
    • Set Variable Random_Number = (Random integer number between 1 and 200)
    • Set Variable Random_Tower_Type = Tower_Type[Random_Number]
Random_Number is an Integer variable. Random_Tower_Type is a Unit-Type variable like Tower_Type, except it's NOT an Array.

Your number range can be used to dictate the grades of towers, for example 1 -> 66 can be low, 67 -> 132 can be mid, and 133+ can be high.

OR, and this may be better since it's easier to add new towers in the future, you would have three Unit-Type array variables:
  • Actions
    • Set Variable Tower_Type_Low[1] = Guard Tower
    • // repeat for all low towers
    • Set Variable Tower_Type_Mid[1] = Arcane Tower
    • // repeat for all mid towers
    • Set Variable Tower_Type_High[1] = Cannon Tower
    • // repeat for all high towers
The logic remains mostly the same, except that low would go from 1 -> 66, mid would go from 1 -> 66, and high would go from 1 -> 66. Then when you generate a random number you would set your range to be between 1 and 66 instead of 1 and 200.

Now the somewhat advanced part would be getting 3 of each Tower_Type at random WITHOUT repeats. This can be done using Arrays and some clever math that I'm too lazy to write here. See Maker's post near the bottom:

After that, I'm not too sure what you'd do to actually add these Tower_Types to your Builder. I suppose using the Limit Construction action would allow you to control what can and can't be built. You'd probably have to add all 200 towers to your Builder in the Object Editor by default and then Disable all of them at the start of the game using this:
  • Player Group - Pick every player in (All players) and do (Actions)
    • Loop - Actions
      • For each (Integer A) from 1 to 200, do (Actions)
        • Loop - Actions
          • Player - Make Tower_Type[(Integer A)] Unavailable for training/construction by (Picked player)
Then you can make them Available again during the random Tower_Type process that I talked about before.
 
Last edited:
Level 2
Joined
Feb 8, 2020
Messages
3
I got it working but it may have been the long way around. I added all the towers to the builder but made them all unbuildable. Then I used the intergers to randomely pick the towers.
 
Top