- Joined
- Jul 10, 2006
- Messages
- 3,315
Introduction
You've probably already worked with
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:
As another example, let's make a spell that has a chance to reset itself.
I'll use Archmage's Water Elemental.
JASS
The JASS code is even smaller and simpler.
Credits to Troll-Brain for the "if UnitRemoveAbility( u, abil )" fix.
I suggest using this for GUI users as well. Using it is easy:
You've probably already worked with
- Unit - Reset ability cooldowns for unit
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
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
-
If - Conditions
-
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
-
Events
- Removing the ability on
- Unit - A unit Starts the effect of an ability
- Reseting on
- Unit - A unit Finishes casting an ability
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
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: