I've made with some help a cooldown system and I want the Heroes to decrease the cooldown by every cast to a minimum time of cooldown. the only issue is that it decreases everytime with 1 no matter what values I write there.
I tried to decrease it with 0.001 or set the value to value*0.99 but again, decreases with 1 and the function runs twice :S it's really strange.
Here's what I got:
Okay I solved the issue with the 1 thing, but the function still runs twice and I don't know why :S:S
I tried to decrease it with 0.001 or set the value to value*0.99 but again, decreases with 1 and the function runs twice :S it's really strange.
Here's what I got:
JASS:
library LearnAbilities initializer InitTrig_Cooldown_set_and_fire uses CDSys
globals
private constant integer HASH = 8192
private real array ABIL
real array abil
private integer array INDEX
integer array index
endglobals
private struct abil
static method operator []= takes integer id, real value returns nothing
set ABIL[id-(id/HASH)*HASH] = R2I(value) // This was the issue should be value instead of R2I(value)
endmethod
static method operator[] takes integer id returns real
return ABIL[id-(id/HASH)*HASH]
endmethod
endstruct
private struct index
static method operator []= takes integer id, integer value returns nothing
set INDEX[id-(id/HASH)*HASH] = value
endmethod
static method operator[] takes integer id returns integer
return INDEX[id-(id/HASH)*HASH]
endmethod
endstruct
function Trig_Learn_ability_Actions takes nothing returns nothing
local integer abi = GetLearnedSkill()
local integer i = index[abi]
local real abil_id = abil<i>
local integer fake = 039;A003039;
if abil_id != 0 then
debug call BJDebugMsg("Ability Id: "+I2S(abi))
debug call BJDebugMsg("Index: "+I2S(i))
debug call BJDebugMsg("Cooldown: "+R2S(abil_id))
if i == 1 then
set fake = 039;A003039;
elseif i == 2 then
set fake = 039;A000039;
elseif i == 3 then
set fake = 039;A001039;
elseif i == 4 then
set fake = 039;A002039;
endif
call UnitAddCooldown(HERO, i, abi,fake,abil_id)
endif
endfunction
function Trig_Cooldown_Add_Actions takes nothing returns nothing
local integer abi = GetSpellAbilityId()
local integer i = index[abi]
local real abil_id = abil<i>
call RunCooldown( GetTriggerUnit(), abi)
call Cooldown(GetTriggerUnit(), i, abil_id)
call BJDebugMsg("Old CD: "+R2S(abil[index[abi]]))
set abil[index[abi]] = abil[index[abi]] * 0.9999
call BJDebugMsg("New CD: "+R2S(abil[index[abi]]))
call TriggerSleepAction( 0.20 )
call SetUnitManaPercentBJ( GetTriggerUnit(), 100 )
endfunction
//===========================================================================
//===========================================================================
function InitTrig_Cooldown_set_and_fire takes nothing returns nothing
local trigger t1 = CreateTrigger( )
local trigger t2 = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( t1, EVENT_PLAYER_HERO_SKILL )
call TriggerAddAction( t1, function Trig_Learn_ability_Actions )
call TriggerRegisterAnyUnitEventBJ( t2, EVENT_PLAYER_UNIT_SPELL_EFFECT )
call TriggerAddAction( t2, function Trig_Cooldown_Add_Actions )
set t1 = null
set t2 = null
set index[039;AHtb039;] = 1
set abil[index[039;AHtb039;]] = 5.
set index[039;AHtc039;] = 2
set abil[index[039;AHtc039;]] = 10.
set index[039;AHav039;] = 3
set abil[index[039;AHav039;]] = 15.
endfunction
endlibrary</i></i>
Okay I solved the issue with the 1 thing, but the function still runs twice and I don't know why :S:S