GetTriggerUnit-
DogEntrepreneur
- Reaction score
- 129
Cooldowns
If you need to check the cooldown of an ability, then it's the snippet you need.
If you have an Idea of a feature I could add, please tell.
The code
If you need to check the cooldown of an ability, then it's the snippet you need.
If you have an Idea of a feature I could add, please tell.
The code
JASS:
library Cooldowns
// ------------------------------------------------------
// Cooldown is a snippet used to archive spell cooldowns.
// ______________________________________________________
//
// If you need to check the cooldown of an ability,
// then it's the snippet you need.
//
// #1 - When the ability is cast, you must register the cooldown
// You must do it because there's no way to get the cooldown of an ability
// as far as I know...
//
// #2 - You can use a function that return boolean (true/false) to check if
// the spell is in cooldown.
//
// #3 - You can get the cooldown of an ability by another function that return real.
//
// 1 - RegisterCd(a unit, the caster / an integer, the id of the ability / a real, the cooldown)
// 2 - IsSpellInCd(a unit, the caster / an integer, the id of the ability)
// 3 - GetSpellCd(a unit, the caster / an integer, the id of the ability)
//
//
//
// How to import?
//
// Create a new trigger called "Cooldowns", convert to custom sciprt and put this script in it.
//
//
globals
private hashtable hasht = InitHashtable()
endglobals
function RegisterCd takes unit u, integer abilityId, real period returns nothing
local integer uId = GetHandleId(u)
local integer aId = abilityId
local real wait = period
local timer tim = LoadTimerHandle(hasht, uId, aId)
// If the timer does not exist, then create one.
if tim == null then
set tim = CreateTimer()
call TimerStart(tim, wait, false, null)
call SaveTimerHandle(hasht, uId, aId, tim)
// If the timer exist, then re-use it.
else
call TimerStart(tim, wait, false, null)
call SaveTimerHandle(hasht, uId, aId, tim)
endif
set tim = null
endfunction
function IsSpellInCd takes unit u, integer abilityId returns boolean
return TimerGetRemaining(LoadTimerHandle(hasht, GetHandleId(u), abilityId)) > 0.00
endfunction
function GetSpellCd takes unit u, integer abilityId returns real
local integer uId = GetHandleId(u)
local integer aId = abilityId
local timer tim = LoadTimerHandle(hasht, uId, aId)
local real r = TimerGetRemaining(tim)
if tim == null then
debug call BJDebugMsg("Attempting to get data from a null timer. Make sure you registered the cooldown well.")
set r = 0.00
endif
set tim = null
return r
endfunction
endlibrary
The map