Snippet Cooldowns

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
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
 

RaiJin

New Member
Reaction score
40
what about spells that have different cooldown's per level?

i don't see the point of using hashtable when you can use jesus4lyf's hashing snippet and just make some global arrays and hash them all in there with the spell ability ID
 

GetTriggerUnit-

DogEntrepreneur
Reaction score
129
JASS:

local real cooldown = 10.00 * I2R(GetUnitAbilityLevel(......))
call RegisterCd(..., ..., cooldown)


Simple.


Does it matter? Using an hashtable require no systems. Using a system for a such little snippet like this would be useless, Imo.
 

Komaqtion

You can change this now in User CP.
Reaction score
469
Couldn't this:
JASS:
    function IsSpellInCd takes unit u, integer abilityId returns boolean
        local integer uId = GetHandleId(u)
        local integer aId = abilityId
        local timer tim = LoadTimerHandle(hasht, uId, aId)
        local boolean bool
        if TimerGetRemaining(tim) > 0.00 then
            set bool = true
        endif
        if TimerGetRemaining(tim) == 0.00 then
            set bool = false
        endif
        set tim = null
        return bool
    endfunction


Be inlined to this:
JASS:
    function IsSpellInCd takes unit u, integer abilityId returns boolean
        return TimerGetRemaining(LoadTimerHandle(hasht, GetHandleId(u), abilityId)) > 0.00
    endfunction
 

RaiJin

New Member
Reaction score
40
JASS:
local real cooldown = 10.00 * I2R(GetUnitAbilityLevel(......))
call RegisterCd(..., ..., cooldown)


Simple.


Does it matter? Using an hashtable require no systems. Using a system for a such little snippet like this would be useless, Imo.

jesus hashing is a snippet, its like having 2 snippets in one and that's what his snippet is made for, these kinds of things. Why not use something that's made for these kinds of things?

and if you have to keep on registering the cooldowns everytime the spell is fired then this is close to useless

i think you should use 1 trigger, when a unit fires a spell then you check if the spell was registered( using jesus hashing snippet ) then you check the cooldown that way..

so users don't have to do the call RegisterCd.... in the function

just a thought though, then again that would make it a system ;3
 

GetTriggerUnit-

DogEntrepreneur
Reaction score
129
I didn't understood the part where you say that the cooldown could be registred alone.

This snippet is not for every ability, it's for a specefic one where you would need to know if an ability is in cooldown / cooldown left.

Why not use something that's made for these kinds of things?
>Aren't hashtables made for these kind of things? I base my snippet of TimerUtils blue 1.23b + later. If vex uses hashtables, why couldn't I?

Changed to Komaqtion's way.
 

Romek

Super Moderator
Reaction score
963
Public functions should have somewhat descriptive names which automatically tell the users what the function does.

The names are generally good except for the 'Cd' abbreviation constantly used. Change all the 'Cd' in the names to 'Cooldown'

Also, I don't like the interface of this. If you wanted to see if 'Cripple' was in cooldown, you'd need to make a new trigger which registers the cooldown everytime it's cast. And the same applies for every spell you want to use this for.
I'd suggest making this detect when a cooldown has started itself, and make the user register a spell with a cooldown once, on map initialization.
 

kingkingyyk3

Visitor (Welcome to the Jungle, Baby!)
Reaction score
216
jesus hashing is a snippet, its like having 2 snippets in one and that's what his snippet is made for, these kinds of things. Why not use something that's made for these kinds of things?

and if you have to keep on registering the cooldowns everytime the spell is fired then this is close to useless

i think you should use 1 trigger, when a unit fires a spell then you check if the spell was registered( using jesus hashing snippet ) then you check the cooldown that way..

so users don't have to do the call RegisterCd.... in the function

just a thought though, then again that would make it a system ;3

+1. If you don't like the hashing, you can use hashtable too.. Why not?
 

oveRLuckEd

New Member
Reaction score
6
This script gives me some errors:
JASS:
line 3 -           hashtable Cooldowns___hasht = InitHashtable()
line 47 -         local integer uId= GetHandleId(u)
line 50 -         local timer tim= LoadTimerHandle(Cooldowns___hasht , uId , aId)
line 55 -         call SaveTimerHandle(Cooldowns___hasht , uId , aId , tim)
line 59 -         call SaveTimerHandle(Cooldowns___hasht , uId , aId , tim)
line 65 -         local integer uId= GetHandleId(u)
line 67 -         local timer tim= LoadTimerHandle(Cooldowns___hasht , uId , aId)
line 80 -         local integer uId= GetHandleId(u)
line 82 -         local timer tim= LoadTimerHandle(Cooldowns___hasht , uId , aId)

I'm using warcraft version 1.23, I tried with JNGP and WE but nothing happened.
Help ?
 

cleeezzz

The Undead Ranger.
Reaction score
268
update to 1.24, this system uses GetHandleId which is only in 1.24

and this will be useful when i stop being lazy and decide to make an AI o_O
 

Romek

Super Moderator
Reaction score
963
JASS:
// On initialization:
call RegisterCooldown(integer spellId, integer level, real time)
// 0 level for all levels.
 

Tom_Kazansky

--- wraith it ! ---
Reaction score
157
I think what Romek said is something like this:

Trigger:
  • Register Cooldown
    • Events
      • Map initialization
    • Conditions
    • Actions
      • -------- register cooldown for Storm Bolt at level 1: 9 (seconds) --------
      • Custom script: call RegisterCooldown( 'AHtb', 1, 9. )
 

Jesus4Lyf

Good Idea™
Reaction score
397
In what situations is this useful?

In most, it would be to know if you can cast the ability... Meaning you want to cast it if you can or something, right? Which means you can use the boolean returned from the issue order command...
Important enquiry.

And that won't work for getting the cooldown on cast, will it?
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top