This "unit indexer" is way too complicated for my brain
) I think i'll just use item inventory slots for ancient protector or some other work around..
Thanks for help anyway!
A Unit Indexer is a very simple system, I'm sure you'd find it easy to use if you spent some time figuring it out (it's worth it).
This particular system automatically runs once you've imported it into your map - so by copying and pasting the folder into the Trigger Editor you're already done.
So what does it do exactly?
All the Unit Indexer does is assign a unique number to each unit in your map, whether they're preplaced or created in the future (trained from a barracks, bought from a merchant, created in a trigger, etc).
How does it do this exactly?
The system assigns this unique number using this
custom value Action:
-
Unit - Create 1 Footman...
-
Unit - Set the custom value of (Last created unit) to 100
100 in that example would be a number that the system has determined isn't being used by another unit.
So if you had 50 Footman running around your map, each of them would be assigned a number between 1 and 50 with NO repeats! It's important that each Footman has it's own unique number because we're going to use this number like an ID to store data to the unit. It's similar to how in real life we all have a unique ID on our driver's license or birth certificate, and it's important that these are different numbers since that's how we can identify one person from another.
Why is all of this useful?
It's useful because of another important thing to understand, Variable
Arrays:
-
Set Variable AbilityPower[1] = 100.00
-
Set Variable AbilityPower[2] = 200.00
-
Set Variable AbilityPower[3] = 300.00
I'm sure you've seen these before, they're just a slightly more advanced version of a normal Variable. An
Array allows us to store a bunch of different data inside of the same Variable as long as we use different [indexes] for each. The [index] is the Integer that you put inside of the variable's brackets [ ].
So in the above example I've stored the value 100.00 at AbilityPower[1], 200.00 at AbilityPower[2], and 300.00 at AbilityPower[3].
How does this tie back into the Unit Indexer and Custom Value?
Simple, we can plug any unit's Custom Values into the [index] of any of our Variable
Arrays to store data directly to that unit:
-
Unit - Create 1 Mountain King...
-
Set Variable AbilityPower[(Custom value of (Last created unit)] = 100.00
-
Unit - Create 1 Archmage...
-
Set Variable AbilityPower[(Custom value of (Last created unit)] = 250.00
In the above example, I've given the Mountain King I just created an AbilityPower value of 100. I've also given the Archmage I just created an AbilityPower value of 250. This value is now stored directly to the heroes and can be referenced from ANY of our other triggers at ANY time!
Here's an example of us referencing it at a later time:
-
Events
-
Unit - A unit Starts the effect of an ability
-
Conditions
-
(Ability being cast) Equal to Storm Bolt
-
(Unit-type of (Casting unit)) Equal to Mountain King
-
Actions
-
Unit - Cause (Casting unit) to deal AbilityPower[(Custom value of (Casting unit))] damage to (Target unit of ability being cast)...
In the above example, our Mountain King's Storm Bolt is going to deal an additional 100.00 damage because we've referenced his AbilityPower[] variable by using his custom value in it's [index].
It's really that simple, just a couple of Actions and a basic understanding of Arrays. Once you understand that, you can proceed to making slightly more advanced triggers with Unit Groups + Loop triggers like I mentioned before. Just take it one step at a time and everything will become much easier to understand.