Uncle, It seems that everything worked out for me. Thank you very much!
Great, feel free to post your triggers so we can double check and ensure that you're doing everything properly.
I'll breakdown how Arrays + the Unit Indexer work in case you're confused about anything. Let's start with Arrays:
-
Set MyIntegerArray[1] = 10
-
Set MyIntegerArray[2] = 4
-
Set MyIntegerArray[3] = 2456
The above trigger is showcasing an Integer array variable I created called
MyIntegerArray. The number inside of the [brackets] is known as the Index of the Array. What this Index does is allow us to turn one variable into multiple instances of itself that can each have their own value. Once you understand how these work it should become clear as to why they're useful in so many different cases.
Now here's why Arrays are useful when combined with a
Unit Indexer system.
There is an Action called Set Custom Value which allows us to attach an Integer to a unit:
-
Unit - Set custom value of (Triggering unit) to 100
This is nice but it's limited to only one custom value per unit. That's not very useful when your map wants to store multiple values per unit and store values that aren't limited to just Integers. That's where the
Unit Indexer comes into play. A
Unit Indexer is a system that takes advantage of this Action by assigning a
unique custom value to each unit in your map. It does this automatically whenever a new unit is created (trained, sold, etc) and for every pre-existing unit at the start of the game. So your very first unit will be given a Custom Value of 1, the second unit will be given a Custom Value of 2, and so on.
But this setting of Custom Value doesn't actually do anything special on it's own. You need to take advantage of it for it to be useful.
Here's an example of how you can take advantage of it using Arrays:
-
Unit - Create 1 Paladin...
-
Set Hero_Luck[(Custom value of (Last created unit))] = 24
-
Unit - Create 1 Warden...
-
Set Hero_Luck[(Custom value of (Last created unit))] = 17
-
Unit - Create 1 Lich...
-
Set Hero_Luck[(Custom value of (Last created unit))] = 30
^ The above trigger uses a new Integer array variable I've created called
Hero_Luck. This is intended to act like a new 4th attribute, which we will use in our other triggers. Here I am assigning the newly created Paladin a Luck stat of 24, the Warden a Luck stat of 17, and the Lich a Luck stat of 30. The reason this works and why there aren't any [index] conflicts is because the Unit Indexer has already assigned
unique Custom Values to each of these Units at the time of creation. Therefore, each Setting of Hero_Luck will use a different [index].
Note that it doesn't have to be an Integer array variable either, you can now attach ANY variable type to your Unit:
-
Unit - Create 1 Paladin...
-
Special Effect - Create a special effect attached to the origin of (Last created unit) using Abilities\Spells\Human\DivineShield\DivineShieldTarget.mdl
-
Set Hero_Special_Effect[(Custom value of (Last created unit))] = (Last created special effect)
^ I've attached a Special Effect to my Paladin. I can now reference this Special Effect at any time by putting the Paladin's Custom Value into the [index] of the
Hero_Special_Effect variable. This would allow me to easily Destroy the effect when my Paladin dies, for example.
Hopefully that all makes sense and you can begin using the simple but very powerful Unit Indexer in more of your triggers
Lastly, here's some important to understand mechanics of Arrays + the Unit Indexer system:
You can't use an Integer larger than 32,768 as an [Index] in an Array. I believe this value was 1/4 the size in earlier versions of Warcraft 3. Luckily, the Unit Indexer takes this into consideration and will stay below that number. When a unit dies, the Unit Indexer recycles their custom value and reserves it to be given to a new unit in the future. This ensures that even if your map spawns in 100,000 units over the course of say an hour, as long as there's never more than 32,768 units on the map
at one time then they will ALL continue to have
unique Custom Values. Basically it's not worth worrying about 99.99% of the time since most maps don't have that many units out at once. Also, recycling custom values is something you should keep in mind. Sometimes you'll want to reset your Arrays back to their default starting values as to prevent future units from inheriting a previous unit's data when the custom value gets recycled. The system actually provides special Events for when a unit becomes Indexed/Recycled, which you can take advantage of here.