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
964
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
964
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.
  • Monovertex Monovertex:
    How are you all? :D
    +1
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though

      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