You copy and paste the "Unit Indexer" folder from this map into your own map. Assuming you haven't already:
Why Unit Indexing is Important For those not familiar with unit indexers such as UnitIndexingUtils, AutoIndex, Perfect Unit Indexing (PUI), Advanced Indexing and Data Storage (AIDS) or Unit Indexer, this can give you a bit of a crash-course. You definitely want to make your spell MUI. To do...
www.hiveworkshop.com
Then you can modify the trigger to work like so:
-
Events
-

Unit - A Unit Starts the effect of an ability
-
Conditions
-

(Ability being cast) Equal to Berserk (Item)
-
Actions
-

Unit - Add Invulnerable (Item) to (Triggering unit)
-

Set Variable CV = (Custom value of (Triggering unit))
-

Set Variable Counter[CV] = (Counter[CV] + 1)
-

Wait 3.00 game-time seconds
-

Set Variable CV = (Custom value of (Triggering unit))
-

Set Variable Counter[CV] = (Counter[CV] - 1)
-

If (All Conditions are True) then do (Then Actions) else do (Else Actions)
-


If - Conditions
-


Then - Actions
-



Unit - Remove Invulnerable (Item) from (Triggering unit)
-


Else - Actions
It's effectively the same trigger, but now you're keeping track of the number of times your unit has used the Item recently with this new
Counter Integer variable.
CV is another Integer variable, but it's optional and only exists to make the trigger easier to work with.
Here's a breakdown of how it works...
Let's pretend that the Item has a 0 second cooldown and
the caster uses the Item three times in a row:
1st: The
Counter variable increased from 0 to 1. The caster is given the Invulnerable ability. A 3.00 second Wait begins.
2nd:
Counter increases from 1 to 2. The caster is given the Invulnerable ability but it fails since it already has it. Another 3.00 second Wait begins.
3rd:
Counter increases from 2 to 3. The caster is given the Invulnerable ability but it fails since it already has it. Another 3.00 second Wait begins.
Now let's pretend that 3.00 seconds of time has passed and all of those Waits have finished. This leads us to the bottom part of our trigger:
-
Set Variable Counter[CV] = (Counter[CV] - 1)
-
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
-

If - Conditions
-

Then - Actions
-


Unit - Remove Invulnerable (Item) from (Triggering unit)
-

Else - Actions
1st: The first Wait finishes and the
Counter variable is reduced from 3 to 2. The If Then Else checks to see if it's equal to 0, it's not.
2nd: Counter reduces from 2 to 1. The If Then Else checks to see if it's equal to 0, it's not.
3rd: Counter reduces from 1 to 0. The If Then Else checks to see if it's equal to 0, and it is zero! That means the (Then - Actions) can finally run, Removing the Invulnerable ability.
Hopefully this clears up why we need the
Counter variable and the issues that we're trying to avoid here. It'd be more clear if you were to use the Item three times spaced out over a short period of time rather than immediately. For example, you use the item, wait 0.50 seconds, use the item again, wait 0.50 seconds, and use the item again. In that situation,
without Counter, your 1st use of the item would Remove the Invulnerable ability early before your 2nd and 3rd uses even had a chance to finish. In other words, all three triggers would be fighting with one another over what to do next.