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

Ordering multiple units to train units to attack

Status
Not open for further replies.
Level 5
Joined
Jun 13, 2015
Messages
129
I've am making a survival type of map where I would want unit production structures to train units which would then seek out enemies to attack. If possible, I would want the production structures to randomly create different units as well.

I have no idea where to start to make the trigger work.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,198
Use an array of unit types. Fill it like a list with all the possible random spawns the building can train. Use a periodic event with timeout less than the fastest training time of all the trainable units to issue the random training order. A random training order is a no target order with the order id the same as the unit type to be trained. One can select a random unit type using a random index from the unit type list (array).

If one wants non equal probabilities to spawn unit types then one needs an additional integer array to store the probability weights and another integer variable to track the total weights. A random integer between 1 and total weight can be processed into a random unit type using a loop that repeatedly subtracts weights until the random number is less than or equal to 0, in which case the current index is the random index to use. Can be optimized using a binary tree, but that is probably overkill for such a simple task as this.

The unit types can also be used with the create unit action instead of training the units directly.

To get the units to attack random victims, use a generic attack random victims trigger. This usually involves periodically picking a subset of units and ordering them to attack a random target, or attack move the ground under them.
 
Level 5
Joined
Jun 13, 2015
Messages
129
Well it is definitely the solution to my problem, but i am not sure of how to use "arrays" or what they are really.
 
Level 9
Joined
Apr 23, 2011
Messages
527
When making a variable, there is an "Array" checkbox. Check that in order to make that variable an array. Basically, you can use one variable for a couple thousand uses, by setting it to different variable indexes.

Say, a unit variable called unit is assigned to a Peasant. For an array:
I could use unit[1] for a Peasant, and then use unit[2] for a Paladin.

Especially useful if you are using loops and want to refer to multiple handles efficiently.
 
Level 5
Joined
Jun 13, 2015
Messages
129
When making a variable, there is an "Array" checkbox. Check that in order to make that variable an array. Basically, you can use one variable for a couple thousand uses, by setting it to different variable indexes.

Say, a unit variable called unit is assigned to a Peasant. For an array:
I could use unit[1] for a Peasant, and then use unit[2] for a Paladin.

Especially useful if you are using loops and want to refer to multiple handles efficiently.

Array data structure - Wikipedia

In JASS (what GUI builds to in WorldEdit) arrays are dynamic arrays and automatically have a size of 32,768 (8,192 in old Warcraft III versions).

I think i have a clearer idea on how to proceed on now. Thank you both!! :)
 
Status
Not open for further replies.
Top