• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Custom Cooldown System Version 0.1

This bundle is marked as useful / simple. Simplicity is bliss, low effort and/or may contain minor bugs.
Custom Cooldown System by neku99

This very flexible very simple system allows you to attach a custom cooldown to any ability you choose with just one function call. In as much as this is a system, I believe this is also serves as a template for a basic custom cooldown system.

I made it because I needed it basically but decided to upload it as I think it'll help people on all of their custom cooldown needs.

This system Requires JassNewGen to be saved

Please check the header for more details on the system.

Credits to:

Berb - For teaching me JASS/vJASS
Adiktuz - For doing the same and having patience for all my vJass Questions

JASS:
//============================================================================================
// Custom Cooldown System v.0.1 
// By neku99
//============================================================================================
// What does this system do?
//==================================================
//
// - This very simple system allows you to attach a custom cooldown to any ability you choose 
// with just one function call
//
//==================================================
// Configurables
//==================================================
// - Well there aren't really, but if you want to experiment with some other cooldown concepts
// then you may use this as a template
// 
//
//==================================================
// Globals
//==================================================
//
// COOL_ARRAY   = an integer array used for the indexing
// COOL_ABIL_ID = an integer array used to store the dummy abilities I used for while abilities are in cooldown
// (I declared the raw codes of the dummy abilities for each slot on the init function on the bottom)
//
// COOL_ TIMER  = a timer used for the Loop
// TOTAL        = an integer used for the indexing
//
//==================================================
// Parameters
//==================================================
// - You can simply use this system using one function call:
//
// call Cool.create( Parameters )
//
// - It is advised that you call this function after an ability is casted to prevent it from
// canceling the ability. I also added example spells in Jass and GUI on how to use the system.
//
// Here are the parameters arranged in order with description
//
// u         = the unit that casted the ability that is being cooled down
// cool      = the cooldown of the ability in seconds
// slot      = the slot number of the ability ( see the Command Card Diagrams on the buttom, under "Dummy Ability Configuration" )
// abilityId = the raw code of the ability
//
//==================================================
// Dummy Ability Configuration
//==================================================
// - In this system I use dummy abilities that will replace the ability while it is cooling down.
// After the cooldwon is finished the dummy ability will be replaced again with the original ability.
// The 4 dummy abilities I used corresponds to the 4 slots in the buttom row of the command card
// 
// - You can just copy the dummy abilities I used on the test map for you to use. But if you want to add more slots,
// here are some guidlines:
//
// + The dummy abilties are recommended to be passive abilities with no effects.
//   I used "Brilliance Aura" for the dummy ability.
//
// + After choosing a base passive ability, create a copy of the base ability for each slot you want to make.
//   Change the names (or the editor suffix) of the dummy abilities according to their slot.
//
// + Now after creating and naming your dummy abilities it's time to set their x,y coordinates according to their positions on the command card
//   - As an example I'll be showing you how I did my dummy abilities
//
//   Command Card(X,Y): The numbers inside are respectively the x,y positions of the slots in the command card
//                   [0,0][1,0][2,0][3,0]
//                   [0,1][1,1][2,1][3,1]
//                   [0,2][1,2][2,2][3,2]
//
//   - My dummy abilities are named according to their slot positions, but are not based on the coordinates but an intiger starting from 1
//     The dummy abilities are:
//     - On Cooldown (Slot 1)
//     - On Cooldown (Slot 2)
//     - On Cooldown (Slot 3)
//     - On Cooldown (Slot 4)
//
//  Command Card(Slot): This is the one I based for the slot numbers
//                   [slot 9][slot 10][slot 11][slot 12]
//                   [slot 5][slot  6][slot  7][slot  8]
//                   [slot 1][slot  2][slot  3][slot  4]
//
//
//   - Next thing you do is set the x,y coordinates of the abilties by editing these fields in the Object Editor:
//    *Art - Button Position - Noramal(X)
//    *Art - Button Position - Noramal(Y)
//
//   - Set the x,y coordinates based on the coordinates (On the "Command Card (X,Y)" diagram)
//     The dummy abilities and their respective x,y positions:
//     - On Cooldown (Slot 1)(0,2)
//     - On Cooldown (Slot 2)(1,2)
//     - On Cooldown (Slot 3)(2,2)
//     - On Cooldown (Slot 4)(3,2)
//
//   -After setting them accordingly it's time for the next step . . .
// + Next we need to set the raw codes of the abilities on the COOL_ABIL_ID array. (It is set at the init function on the buttom)
//   - To see the raw codes of the abilities in the Object Editor, you need to go to
//     View and check the "Disply Values As Raw Data" or simply enter CTRL + D
//     doing this will let you see the raw codes of everything from units to abilities
//   - Now that you've seen the raw codes of the dummy abilities it's just a case of copying it and setting it in the init function
//
// + SETTING IT UP +
//   - First remember that Slot 1 = Coordinate (0,2), Slot 2 = Coordinate (1,2), and so on. Now setting it up is pretty easy.
//     
//   As one example (Since I already have set 4 on the init function) on how to set it up:
//
//           set COOL_ABIL_ID[SlotNumberHere] = 'RawCodeHere'
//           set COOL_ABIL_ID[       1      ] = '    A00A   ' //Dummy ability for slot 1
//
// + And presto! you just made the dummy abilties
//
//==================================================
// Ending Comments
//==================================================
// - This will be the first Jass/vJass coded system/spell submmiting
// - If you find any bugs or you have any suggestions contact me. neku99
// - If you use this on any map of your's never forget to give credits :D
// - I left Debug messages that can be deleted and will not affect code
//   Any call that has "//DEBUG MESSAGE YOU CAN DELETE THIS" can be removed
//
//==================================================
// Credits to
//==================================================
// Berb    - For teaching me JASS/vJASS
// Adiktuz - For doing the same and having patience for all my vJass Questions
//  
//END/////////////////////////////////////////////////////////////////////////////////////////

library CustomCooldown initializer init
    globals
        private integer array COOL_ARRAY[8190]
        private integer array COOL_ABIL_ID
        
        private integer TOTAL       = 0
        private timer COOL_TIMER    = CreateTimer()
        
        private constant real TICK  = 0.1    
    endglobals
    
  struct Cool
    
    private unit u = null
    private real cool
    private integer slot
    private integer abilityId
    
    private static thistype data
    
    private static method Loop takes nothing returns nothing
        local integer i = 1

        loop
            exitwhen i > TOTAL
            set data = COOL_ARRAY[i]
            
              call ClearTextMessages()
              call BJDebugMsg( GetAbilityName(data.abilityId) + " Cooldown = " + R2S(data.cool))//DEBUG MESSAGE YOU CAN DELETE THIS
              
              if data.cool > 1.0 then

                 set data.cool = data.cool - TICK
              else
                 call BJDebugMsg("RE-ADD/REMOVE")//DEBUG MESSAGE YOU CAN DELETE THIS
                 call UnitRemoveAbility( data.u, COOL_ABIL_ID[data.slot])
                 call UnitAddAbility( data.u, data.abilityId )
                 set COOL_ARRAY[i] = COOL_ARRAY[TOTAL]
                 set TOTAL = TOTAL - 1
                 set i = i - 1
                     
                 call BJDebugMsg("DATA DESTROY")//DEBUG MESSAGE YOU CAN DELETE THIS
                 call data.destroy()
              endif
                            
              if TOTAL == 0 then
                 call BJDebugMsg("PAUSE TIMER")//DEBUG MESSAGE YOU CAN DELETE THIS
                 call PauseTimer(COOL_TIMER)
              endif
              
              set i = i + 1
           endloop        
    endmethod
    
    static method create takes unit u, real cool, integer slot, integer abilityId returns thistype
        
        set TOTAL = TOTAL + 1

        set data = allocate()
        
        set data.u         = u
        set data.cool      = cool
        set data.slot      = slot
        set data.abilityId = abilityId
        
        call UnitRemoveAbility( u, abilityId)
        call UnitAddAbility( u, COOL_ABIL_ID[slot] )
        call BJDebugMsg("ADD/REMOVE")//DEBUG MESSAGE YOU CAN DELETE THIS
        set COOL_ARRAY[TOTAL] = data
        
        if TOTAL == 1 then
            call BJDebugMsg("TIMER START")//DEBUG MESSAGE YOU CAN DELETE THIS
            call TimerStart( COOL_TIMER, TICK, true, function Cool.Loop)
        endif
        
        return data
    endmethod
  endstruct
    
    private function init takes nothing returns nothing
    
        set COOL_ABIL_ID[1] = 'A00A' //Dummy ability for slot 1
        set COOL_ABIL_ID[2] = 'A00B' //Dummy ability for slot 2
        set COOL_ABIL_ID[3] = 'A00D' //Dummy ability for slot 3
        set COOL_ABIL_ID[4] = 'A007' //Dummy ability for slot 4
        
    endfunction
endlibrary

Keywords:
custom, cooldown, system, neku99, vjass, jass, system
Contents

Neku's Lab [Custom Cooldown System] (Map)

Reviews
http://www.hiveworkshop.com/forums/spells-569/identify-system-1-00-a-183934/?prev=r%3D20%26status%3Dr2%26page%3D4113:31, 4th Mar 2011 Bribe: Debug messages still need to be adjusted, GetAbilityName is a BJ that can be optimized... and I left a...

Moderator

M

Moderator

http://www.hiveworkshop.com/forums/spells-569/identify-system-1-00-a-183934/?prev=r%3D20%26status%3Dr2%26page%3D4113:31, 4th Mar 2011
Bribe:

Debug messages still need to be adjusted, GetAbilityName is a BJ that can be optimized... and I left a review detailing more changes.

Status: Rejected until updated
 
Level 10
Joined
Sep 3, 2009
Messages
458
JASS:
call BJDebugMsg("ADD/REMOVE")//DEBUG MESSAGE YOU CAN DELETE THIS
Since you are already using vJASS, you can just write debug call .. and allow the user to enable the debugs whenever he needs to. By the way, way to many debug messages.

debug call? lol didn't know about that something like that how does it work? And I used the debug messages cause there was some weird bug I was fixing and couldn't find it so I used those messages XD. Should I remove them?

Idk if this is more efficient then use some attachment system instead a index and loop.. probably someone which understand more about speed and execution can explain better it

attachment system? I don't know what attachment systems are ehehe and looping and indexing is all I know for now, I'm pretty new to vJass as it is.
 
Level 10
Joined
Sep 3, 2009
Messages
458
nice idea but a better cooldown indication would be awesome though I have no idea how it should look like
maybe this could be helpful or not
http://www.thehelper.net/forums/showthread.php?t=118557

Thanks! glad you like it . . . but as you already now, if you tested the map (did you? XD) this system doesn't really go with warcrafts cooldown system. So it really won't show the cooldown indication as the system replaces it with a passive dummy ability while it's cooling down.
 
Level 7
Joined
Oct 11, 2008
Messages
304
@Windu

it remove the ability casted and add some dummy spell, when timer over, it add back and remove the dummy spell


@On-Topic

I tested it and the only problem for it that you can't what's the cooldown of the ability, only if you use debug message...

I tried to find some way to display the cooldown time but nothing...

@neku99

Attachment system which I said is like TimerUtils, Key Timer 2, ABC, etc :p
about the debug... it is:

call BJDebugMsg(..

>>

debug call BJDebugMsg(..

this function will be only called if in debug mode (JassHelper tab has that option)


EDIT: I just notice that now, you forget to store the leve of ability :p
 
Level 19
Joined
Feb 4, 2009
Messages
1,313
I just got an idea
someone at wc3c made a system called "DGUI" or something
it can move units so they stay at the same place when you are rotating your camera
you could make models looking like buttons and change their animation speed based on the cooldown time
dynamic texture swapping with the eattree ability might be helpful to decrease the number of dummy units required to one
(there is a system for that at wc3c, too)

edit:
DGUI
http://www.wc3c.net/showthread.php?t=102351
DUSC
http://www.wc3c.net/showthread.php?p=1043980#post1043980
 
Level 10
Joined
Sep 3, 2009
Messages
458
Eccuse me, but what exactle is a "custom cooldown" ? Does it show a graphic of the cooldown or make the spells uncastable in a different way? I don't really understand from the description.

First, for example You just finished casting the Ice Nova Spell. The system will replace Ice Nova with a dummy passive ability. The dummy ability will stay there until the cooldown is finished, preventing the unit from casting it again.

I should have explained it in more detail how it works. I'll update as soon as I can.

@Windu

it remove the ability casted and add some dummy spell, when timer over, it add back and remove the dummy spell


@On-Topic

I tested it and the only problem for it that you can't what's the cooldown of the ability, only if you use debug message...

I tried to find some way to display the cooldown time but nothing...

@neku99

Attachment system which I said is like TimerUtils, Key Timer 2, ABC, etc :p
about the debug... it is:

call BJDebugMsg(..

>>

debug call BJDebugMsg(..

this function will be only called if in debug mode (JassHelper tab has that option)


EDIT: I just notice that now, you forget to store the leve of ability :p

Hmm indeed you can only view it through debug messages and or multiboard. I am thinking of a much graphical oriented way on showing how much time the cooldown has, but i think it'll do a number on the size of the map. BUt I could be wrong.

Attachment systems like that are pretty alien to me. But I guess mys system is highly configurable for anything you want to integrate it with ( mostly ) but ima check those TimerUtils and the other things out.

wow the debug is pretty neat. Ima edit the code when I have time. Pretty busy at the moment
 
Level 6
Joined
Mar 26, 2008
Messages
239
You could make it much better by adding some "cooldown display" features, for example:
- Make not 1 ability "Cooldown", which will change during the cooldown time. Each ability "Cooldown" will have it's own icon, so u can see it's cooldown (for example icons 10-9-8-7....-1 with changing every second, but it's bad for high cooldown spells, or icons like visages damaage count in dota which will change in period, which depends on actual cooldown, which is better to use)

I can do it myself (for example if I use it in my map), but I think if u do it and post here it'll be helpful to many people ^^
 
Level 10
Joined
Sep 3, 2009
Messages
458
You could make it much better by adding some "cooldown display" features, for example:
- Make not 1 ability "Cooldown", which will change during the cooldown time. Each ability "Cooldown" will have it's own icon, so u can see it's cooldown (for example icons 10-9-8-7....-1 with changing every second, but it's bad for high cooldown spells, or icons like visages damaage count in dota which will change in period, which depends on actual cooldown, which is better to use)

I can do it myself (for example if I use it in my map), but I think if u do it and post here it'll be helpful to many people ^^

I'm planning on doing the exact same thing. But I havent done it yet for some reason ahaha. Well I guess Ima just make this system like a template thingy for custom cooldowns, so that people can experiment with themselves. So it'll be open source? is that the right term?
 
Top