- Joined
- Feb 6, 2014
- Messages
- 2,466
A System that allows you to trigger an ability's cooldown (still showing the cooldown indicator). Still have some issues though.
Example of using it:
So while it is on cooldown, they are temporary easier to kill.
Any feedback?
JASS:
// ---------------------------------------------------------------- //
// Trigger Cooldown System v1.00 by Flux //
// ---------------------------------------------------------------- //
// //
// This system allows you to make any unit's ability goes into cooldown via trigger //
// Though written in Jass, it has GUI support and easy to use for GUI users //
// //
// HOW TO USE: //
// 1. Set the TCD_Unit variable. This refers to the unit that will have its ability //
// goes into cooldown via trigger. //
// 2. Set the TCD_Ability variable. This refers to the ability that will go into cooldown. //
// 3. Set the TCD_DummyAbility variable. This refers to the ability based on Spell Shield //
// that you have created. It must have the same tooltip, manacost and icon. //
// 4. Set the TCD_Time variable. This refers how long the TCD_Ability will be replaced by //
// the TCD_DummyAbility. It should match the 'Stats - Cooldown' of the TCD_DummyAbility. //
// 5. Set the TCD_Manacost variable. This is the manacost of the TCD_Ability which should //
// match the manacost of the TCD_DummyAbility 'Stats - Manacost' //
// 6. Execute by "Trigger - Run Trigger Cooldown System <gen> (ignoring conditions)" //
// //
// //
// //
// //
// //
// KNOWN ISSUE: //
// - When triggering the cooldown of an active ability, it will reset the original //
// ability's cooldown. Example: Original Ability's cooldown is 20 seconds but //
// the triggered cooldown only last 5 seconds, when that 5 seconds is finished, //
// the original ability is now ready to use again. //
// - Can only trigger Unit ability so far, so to trigger a Hero's ability, a dummy hero //
// ability must be used and when the dummy ability is learned, add the real ability. //
// (As shown in Map Demo 2) //
// - Removes Invisibility.
// - Triggering a Cycloned unit's ability will reset its cooldown.
function Trig_Trigger_Cooldown_System_TimerExpires takes nothing returns nothing
local timer t = GetExpiredTimer()
local integer id = GetHandleId(t)
local unit u = LoadUnitHandle(udg_TCD_Hashtable, id, 0)
local integer origAbil = LoadInteger(udg_TCD_Hashtable, id, 0)
local integer lvl = LoadInteger(udg_TCD_Hashtable, id, 1)
local integer fakeAbil = LoadInteger(udg_TCD_Hashtable, id, 2)
call UnitAddAbility(u, origAbil)
if lvl > 1 then
call SetUnitAbilityLevel(u, origAbil, lvl)
endif
call UnitRemoveAbility(u, fakeAbil)
call BJDebugMsg("Original Ability added")
//Destroy the timer reference data
call FlushChildHashtable(udg_TCD_Hashtable, id)
//Destroy the unit reference data
call FlushChildHashtable(udg_TCD_Hashtable, GetHandleId(u))
call PauseTimer(t)
call DestroyTimer(t)
set t = null
endfunction
function Trig_Trigger_Cooldown_System_Actions takes nothing returns nothing
local timer t
local integer id
local integer unitId
local integer lvl
set lvl = GetUnitAbilityLevel(udg_TCD_Unit, udg_TCD_Ability)
if lvl > 0 then
call UnitRemoveAbility(udg_TCD_Unit, udg_TCD_Ability)
else
set lvl = GetUnitAbilityLevel(udg_TCD_Unit, udg_TCD_DummyAbility)
call UnitRemoveAbility(udg_TCD_Unit, udg_TCD_DummyAbility)
endif
//Add the fake ability
call UnitAddAbility(udg_TCD_Unit, udg_TCD_DummyAbility)
call SetUnitAbilityLevel(udg_TCD_Unit, udg_TCD_DummyAbility, lvl)
//Trigger the Cooldown Indicator
call SetUnitX(udg_TCD_DummyCaster, GetUnitX(udg_TCD_Unit))
call SetUnitY(udg_TCD_DummyCaster, GetUnitY(udg_TCD_Unit))
call BJDebugMsg("TCD system executed")
if IssueTargetOrderById(udg_TCD_DummyCaster, 852075, udg_TCD_Unit) then
call BJDebugMsg("success")
set unitId = GetHandleId(udg_TCD_Unit)
//[unitId][5] is for timers
//If there is already a timer, just reset it
if HaveSavedHandle(udg_TCD_Hashtable, unitId, 5) then
set udg_TCD_Time = LoadReal(udg_TCD_Hashtable, unitId, 6)
call TimerStart(LoadTimerHandle(udg_TCD_Hashtable, unitId, 5), udg_TCD_Time, false, function Trig_Trigger_Cooldown_System_TimerExpires)
call BJDebugMsg("timer already existing, time = " + R2S(udg_TCD_Time))
else
call BJDebugMsg("new timer created time = " + R2S(udg_TCD_Time))
set t = CreateTimer()
set id = GetHandleId(t)
//Save the timer in reference to the unit
call SaveTimerHandle(udg_TCD_Hashtable, unitId, 5, t)
//Save the cooldown time in reference to the unit
call SaveReal(udg_TCD_Hashtable, unitId, 6, udg_TCD_Time)
call TimerStart(t, udg_TCD_Time, false, function Trig_Trigger_Cooldown_System_TimerExpires)
set t = null
//Save the unit
call SaveUnitHandle(udg_TCD_Hashtable, id, 0, udg_TCD_Unit)
//Save the original ability replaced
call SaveInteger(udg_TCD_Hashtable, id, 0, udg_TCD_Ability)
//Save the level of the original ability
if lvl > 1 then
call SaveInteger(udg_TCD_Hashtable, id, 1, lvl)
endif
//Save the fake ability
call SaveInteger(udg_TCD_Hashtable, id, 2, udg_TCD_DummyAbility)
endif
if udg_TCD_Manacost > 0 then
call SetUnitState(udg_TCD_Unit, UNIT_STATE_MANA, GetUnitState(udg_TCD_Unit, UNIT_STATE_MANA) + udg_TCD_Manacost)
endif
else
call UnitAddAbility(udg_TCD_Unit, udg_TCD_Ability)
if lvl > 1 then
call SetUnitAbilityLevel(udg_TCD_Unit, udg_TCD_Ability, lvl)
endif
call UnitRemoveAbility(udg_TCD_Unit, udg_TCD_DummyAbility)
endif
endfunction
//===========================================================================
function InitTrig_Trigger_Cooldown_System takes nothing returns nothing
set gg_trg_Trigger_Cooldown_System = CreateTrigger( )
set udg_TCD_DummyCaster = CreateUnit(Player(14), 'Htcd', 0, 0, 0)
set udg_TCD_Hashtable = InitHashtable()
call SetHeroLevel(udg_TCD_DummyCaster, 6, false)
call UnitAddAbility(udg_TCD_DummyCaster, 'Atcd')
call SelectHeroSkill(udg_TCD_DummyCaster, 'Atcd')
call TriggerAddAction(gg_trg_Trigger_Cooldown_System, function Trig_Trigger_Cooldown_System_Actions)
endfunction
Example of using it:
-
Trigger Cooldown by Esc
-
Events
-
Player - Player 1 (Red) skips a cinematic sequence
-
-
Conditions
-
Actions
-
Unit Group - Pick every unit in (Units in (Playable map area) matching ((Unit-type of (Matching unit)) Equal to Mountain Giant)) and do (Actions)
-
Loop - Actions
-
-------- Set the unit --------
-
Set TCD_Unit = (Picked unit)
-
-------- Set the original ability --------
-
Set TCD_Ability = Hardened Skin (Mountain Giant)
-
-------- Set the fake ability based on Spell Shield --------
-
Set TCD_DummyAbility = Hardened Skin (For TCD System)
-
-------- TCD_Time = How much time you want the spell to be on cooldown --------
-
-------- It must match the TCD_DummyAbility 'Stats - Cooldown' --------
-
Set TCD_Time = 5.00
-
-------- Set the manacost of the ability --------
-
Set TCD_Manacost = 0.00
-
Trigger - Run Trigger Cooldown System <gen> (ignoring conditions)
-
-
-
-
So while it is on cooldown, they are temporary easier to kill.
Any feedback?
Attachments
Last edited: