I'm currently making a cooldown system for my map. It's a basic idea to make cooldowns dynamic. You cast the spell, it starts a timer, adds a fake icon to the unit and after some seconds changes back to normal, so you can use the ability again, simple. But I want to change the cooldown as the skill cools down. examples help a lot:
- Mountain King casts Thunder Clap (removes real skill, adds fake, starts timer with 10 second time)
- Another skill or item or something takes effect and the cooldown will be reduced to 8 seconds.
How to make that?
Here's the cooldown-system (maybe a snippet) I wrote :
- Mountain King casts Thunder Clap (removes real skill, adds fake, starts timer with 10 second time)
- Another skill or item or something takes effect and the cooldown will be reduced to 8 seconds.
How to make that?
Here's the cooldown-system (maybe a snippet) I wrote :
JASS:
library CDLibrary
globals
endglobals
struct CD
unit u
integer a_real
integer a_fake
real dur
effect eff
endstruct
private function CDCallback takes nothing returns nothing
local CD cd = GetTimerStructA(GetExpiredTimer())
call UnitRemoveAbility(cd.u, cd.a_fake)
call UnitAddAbility(cd.u, cd.a_real)
call ClearTimerStructA(GetExpiredTimer())
endfunction
function Cooldown takes unit u, integer ability_real, integer ability_fake, real duration returns nothing
local CD cd = CD.create()
local timer t = CreateTimer()
set cd.u = u
set cd.a_real = ability_real
set cd.a_fake = ability_fake
set cd.dur = duration
call UnitRemoveAbility(cd.u, cd.a_real)
call UnitAddAbility(cd.u, cd.a_fake)
call SetTimerStructA(t, cd)
call TimerStart(t, duration, false, function CDCallback)
set t = null
endfunction
endlibrary