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