• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[GUI] How to reset cooldown for one ability

Level 25
Joined
Jul 10, 2006
Messages
3,315
Introduction
You've probably already worked with
  • Unit - Reset ability cooldowns for unit
or at least seen it in action in maps like DotA.

If you haven't, there is a nasty side to this action: since it affects all cooldowns for the unit, you cannot refresh only a chosen spell.

Method, GUI
Look at the following code:
  • Set ResetUnit = Paladin 0001 //unit that needs a cooldown reset
  • Set ResetAbility = Holy Light //ability that must be reset
  • Set AbilityLevel = (Level of ResetAbility for ResetUnit)
  • Unit - Remove ResetAbility from ResetUnit
  • Unit - Add ResetAbility to ResetUnit
  • Unit - Set level of ResetAbility for ResetUnit to AbilityLevel
Without using the aforementioned action, we can reset the cooldown for our chosen ability by simply removing and re-adding it to our unit.

As another example, let's make a spell that has a chance to reset itself.

I'll use Archmage's Water Elemental.
  • Reset Water Elemental
    • Events
      • Unit - A unit Finishes casting an ability
    • Conditions
      • (Ability being cast) Equal to Summon Water Elemental
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Random percentage) Less than or equal to 50.00
        • Then - Actions
          • Set ResetUnit = (Triggering unit)
          • Set ResetAbility = Summon Water Elemental
          • Set AbilityLevel = (Level of ResetAbility for ResetUnit)
          • Unit - Remove ResetAbility from ResetUnit
          • Unit - Add ResetAbility to ResetUnit
          • Unit - Set level of ResetAbility for ResetUnit to AbilityLevel
        • Else - Actions
Some things to note:
  • Removing the ability on
    • Unit - A unit Starts the effect of an ability
    causes the ability to not cast, but still drain the caster's mana.
  • Reseting on
    • Unit - A unit Finishes casting an ability
    Only triggers when the unit finishes its
    Art - Animation - Cast Backswing time.
    In the Archmage example, if you animation cancel (order him to do something before he's finished animating, but after the unit has been summoned), the event won't trigger.
  • Reseting a transformation ability reverts the unit to its normal form. Works for hero transformations.

JASS
The JASS code is even smaller and simpler.
JASS:
function ResetUnitAbilityCooldown takes unit u, integer abil returns nothing
    local integer l = GetUnitAbilityLevel( u, abil )
    if UnitRemoveAbility( u, abil ) then
        call UnitAddAbility( u, abil )
        call SetUnitAbilityLevel( u, abil, l )
    endif
endfunction
Credits to Troll-Brain for the "if UnitRemoveAbility( u, abil )" fix.

I suggest using this for GUI users as well. Using it is easy:
  • Set ResetUnit = Demon Hunter 0005
  • Set ResetAbility = Metamorphosis
  • Custom script: call ResetUnitAbilityCooldown(udg_ResetUnit, udg_ResetAbility)
 
Last edited:
Level 30
Joined
Jul 23, 2009
Messages
1,033
I figured out a way to reset the cooldown of one ability inside a spellbook.
Here is how I did it: I have one spellbook with my spells in. Let's call this spellbook A. The spell I want to reset is Spell A in spellbook A. I have to make a hidden Spellbook. Spellbook B. This hidden spellbook must contain yet another Spellbook (Spellbook C) which also contains Spell A. Spellbook C must share Order ID with Spellbook A. Spellbook C must have a unique ID. When I want to reset the Cooldown on spell A I must remove Spell A from the hero and then Add Spellbook C to the hero. He will now get the ability back, ready to be cast.

However this closes the spellbook but it can be forced to be opened by forcing a keyboard action through triggers but the function will be crude. Also I guess the spellbooks, despite being hidden will get duplicated forever since you never remove them and this probably can lead to a leak and a crash. However, it works.
 
Level 21
Joined
Mar 27, 2012
Messages
3,232
I figured out a way to reset the cooldown of one ability inside a spellbook.
Here is how I did it: I have one spellbook with my spells in. Let's call this spellbook A. The spell I want to reset is Spell A in spellbook A. I have to make a hidden Spellbook. Spellbook B. This hidden spellbook must contain yet another Spellbook (Spellbook C) which also contains Spell A. Spellbook C must share Order ID with Spellbook A. Spellbook C must have a unique ID. When I want to reset the Cooldown on spell A I must remove Spell A from the hero and then Add Spellbook C to the hero. He will now get the ability back, ready to be cast.

However this closes the spellbook but it can be forced to be opened by forcing a keyboard action through triggers but the function will be crude. Also I guess the spellbooks, despite being hidden will get duplicated forever since you never remove them and this probably can lead to a leak and a crash. However, it works.

And if you remove the spellbook instead of the ability it contains, then it will be perfect. In case the command card doesn't update you can also force a spellbook open and close.
 
Top