Cooldown system issues

Nexor

...
Reaction score
74
Sorry for doubleposting, but I have to.

I found out, that there is 0 instances initialized, so the multiboard update trigger will write out the first cast for each player. That's the problem. I need it get working, kingkingy you know a solution to this?
 

Nexor

...
Reaction score
74
Hm, thank you ! :)

Another question to this, and I think the last one :)

How can I make it in the multiboard to appear the ability as a passive ( it writes simply "passive") when the initial cooldown was set to 0 ?
 

Nexor

...
Reaction score
74
Hi again, I think I finally got working the system I wanted with the help of kingkingyyk3.

Here are the triggers of the system:

JASS:
library Cooldown initializer Init requires PUI, ABC
    
    globals
        constant integer MAX_ABILITY = 4
        integer array DisabledAbilities
        private constant integer MaxAbilityPlusOne = MAX_ABILITY + 1
        private player PLAYER
    endglobals
    
    struct Slot extends array
        private static integer array Data
        
        static method operator []= takes integer id, integer value returns nothing
            set thistype.Data[id-(id/8191)*8191] = value
        endmethod
        
        static method operator[] takes integer id returns integer
            return thistype.Data[id-(id/8191)*8191]
        endmethod
        
    endstruct

    struct Cooldown extends array
        private static hashtable ht = InitHashtable()
        
        static method operator [] takes integer id returns thistype
            return id
        endmethod
                
        method operator [] takes integer level returns real
            return LoadReal(thistype.ht,this,level)
        endmethod
                
        method operator []= takes integer level, real value returns nothing
            call SaveReal(thistype.ht,this,level,value)
        endmethod
    endstruct
    
    struct HeroAbilities extends array
        private static hashtable ht = InitHashtable()
        
        static method operator [] takes integer pos returns thistype
            return pos
        endmethod
        
        method operator [] takes integer pos returns integer
            return LoadInteger(thistype.ht,this,pos)
        endmethod
        
        method operator []= takes integer pos, integer value returns nothing
            call SaveInteger(thistype.ht,this,pos,value)
        endmethod
    endstruct
    
    public struct Data
        unit hero
        timer array t [MaxAbilityPlusOne]
        boolean array ready [MaxAbilityPlusOne]
        integer array uses [MaxAbilityPlusOne]
        
        static method expire takes nothing returns nothing
            call PauseTimer(GetExpiredTimer())
        endmethod
        
        method reset takes integer pos returns nothing
            set .ready[pos] = true
            call PauseTimer(.t[pos])
            call TimerStart(.t[pos],0.,false,function thistype.expire)
            set PLAYER = GetOwningPlayer(.hero)
            call SetPlayerAbilityAvailable(PLAYER,DisabledAbilities[pos],false)
            call SetPlayerAbilityAvailable(PLAYER,HeroAbilities[GetUnitTypeId(.hero)][pos],true)
            call UnitResetCooldown(.hero)
        endmethod
        
        method resetall takes nothing returns nothing
            local integer i = 1
            loop
                call .reset(i)
                exitwhen i == MAX_ABILITY
                set i = i + 1
            endloop
        endmethod
        
        static method removeCooldown takes nothing returns nothing
            call thistype(GetTimerStructA(GetExpiredTimer())).reset(GetTimerStructB(GetExpiredTimer()))
        endmethod
        
        method add takes integer id returns nothing
            local integer abil_id = id
            local integer pos = Slot[abil_id]
            local integer lv = GetUnitAbilityLevel(.hero,abil_id)
            if .t[pos] == null then
                set .t[pos] = CreateTimer()
                call SetTimerStructA(.t[pos],this)
                call SetTimerStructB(.t[pos],pos)
            endif
            set .ready[pos] = false
            set PLAYER = GetOwningPlayer(.hero)
            call SetPlayerAbilityAvailable(PLAYER,abil_id,false)
            call SetPlayerAbilityAvailable(PLAYER,DisabledAbilities[pos],true)
            call TimerStart(.t[pos],Cooldown[abil_id][lv],false,function thistype.removeCooldown)
            set .uses[pos] = .uses[pos] + 1
        endmethod
        
        method isReady takes integer abil_id returns boolean
            if TimerGetRemaining(.t[Slot[abil_id]]) <= 0 then
                return true
            endif
            return .ready[Slot[abil_id]]
        endmethod
        
        method pause takes integer abil_id returns nothing
            call PauseTimer(.t[Slot[abil_id]])
        endmethod
        
        method remaining takes integer abil_id returns real
            if .ready[Slot[abil_id]]==true then
                return 0
            endif
            return TimerGetRemaining(.t[Slot[abil_id]])
        endmethod
        
        method multiply takes integer abil_id, real multiplier returns nothing
            local integer pos = Slot[abil_id]
            local integer lv = GetUnitAbilityLevel(.hero,abil_id)
            if .remaining(abil_id)*multiplier >= 0 then
                call PauseTimer(.t[Slot[abil_id]])
                call TimerStart(.t[pos],.remaining(abil_id)*multiplier,false,function thistype.removeCooldown)
            endif
        endmethod
        
        method multiplyall takes real multiplier returns nothing
            local integer i = 1
            local integer id = 0
            
            loop
                set id = HeroAbilities[GetUnitTypeId(.hero)]<i>
                call .multiply(id,multiplier)
                exitwhen i == MAX_ABILITY
                set i = i + 1
            endloop
        endmethod
        
        method increase takes integer abil_id, real inc returns nothing
            local integer pos = Slot[abil_id]
            local integer lv = GetUnitAbilityLevel(.hero,abil_id)
            call PauseTimer(.t[Slot[abil_id]])
            call TimerStart(.t[pos],.remaining(abil_id)+inc,false,function thistype.removeCooldown)
        endmethod
        
        method increaseall takes real inc returns nothing
            local integer i = 1
            local integer id = 0
            
            loop
                set id = HeroAbilities[GetUnitTypeId(.hero)]<i>
                call .increase(id,inc)
                exitwhen i == MAX_ABILITY
                set i = i + 1
            endloop
        endmethod
        
        method restart takes integer abil_id returns nothing
            local integer i = Slot[abil_id]
            call .reset(i)
            call .add(abil_id)
        endmethod
        
        static method create takes unit hero returns thistype
            local thistype this = thistype.allocate()
            local integer i = 0
            
            loop
                set .uses<i> = 0
                exitwhen i == MAX_ABILITY
                set i = i + 1
            endloop
            set .hero = hero
            return this
        endmethod
        //! runtextmacro PUI()
    endstruct
    
    
    private function Cond takes nothing returns boolean
        if IsUnitType(GetTriggerUnit(), UNIT_TYPE_HERO) == true then
            if Data[GetTriggerUnit()] == 0 then
                set Data[GetTriggerUnit()] = Data.create(GetTriggerUnit())
            endif
            call Data(Data[GetTriggerUnit()]).add(GetSpellAbilityId())
        endif
        
        //call BJDebugMsg(&quot;Casting Player: &quot;+GetPlayerName(GetTriggerPlayer()))
        //call BJDebugMsg(&quot;Index of casting unit: &quot;+I2S(GetUnitIndex(GetTriggerUnit())))
        //call BJDebugMsg(&quot;Instance of Data: &quot;+I2S(Data[GetTriggerUnit()]))
        //call BJDebugMsg(&quot;Initial cooldown: &quot;+R2S(Cooldown[GetSpellAbilityId()][GetUnitAbilityLevel(GetTriggerUnit(),GetSpellAbilityId())]))
        //call BJDebugMsg(&quot;Timer&#039;s value: &quot;+R2S(Data(GetTriggerUnit()).remaining(GetSpellAbilityId())))
        return false
    endfunction
    
    
    function Init_Actions takes nothing returns nothing
        local integer id
        local integer i = 1
        if IsUnitType(GetEnumUnit(), UNIT_TYPE_HERO) == true then
            set Cooldown_Data[GetEnumUnit()] = Cooldown_Data.create(GetEnumUnit())
            if GetUnitAbilityLevel(GetEnumUnit(),DisabledAbilities[1]) == 0 then
                loop
                    call UnitAddAbility(GetEnumUnit(),DisabledAbilities<i>)
                    call SetPlayerAbilityAvailable(GetOwningPlayer(GetEnumUnit()),DisabledAbilities<i>,false)
                    exitwhen i == 4
                    set i = i + 1
                endloop
            endif
        endif
    endfunction

    function ReturnTrue takes nothing returns boolean
        return true
    endfunction

    function DataInit takes nothing returns nothing
        local group g = CreateGroup()
        call GroupEnumUnitsInRect(g,bj_mapInitialPlayableArea,Condition(function ReturnTrue))
        call ForGroup( g, function Init_Actions )
        call DestroyGroup(g)
        set g = null
    endfunction
    
    private function Init takes nothing returns nothing
        local trigger trig = CreateTrigger()
        local trigger t= CreateTrigger(  )
        
        call TriggerRegisterTimerEvent( t, 0.01,false )
        call TriggerAddAction( t, function DataInit )
        call TriggerRegisterAnyUnitEventBJ(trig,EVENT_PLAYER_UNIT_SPELL_ENDCAST)
        call TriggerAddCondition(trig,Condition(function Cond))
        
        set DisabledAbilities[1] = &#039;A000&#039;
        set DisabledAbilities[2] = &#039;A001&#039;
        set DisabledAbilities[3] = &#039;A002&#039;
        set DisabledAbilities[4] = &#039;A003&#039;
        
        set t = null
        set trig = null
    endfunction
    
endlibrary</i></i></i></i></i>


Some skills aren't working, like Mirror Image, but I don't need one, it was an accident I tried that skill (and found, that is bugged with this system)

You can setup abilities like this:

JASS:
library InitCD initializer InitTrig_Settings requires Cooldown //===========================================================================
        private function InitTrig_Settings takes nothing returns nothing
            local integer id
            //Archmage skills
            set id = &#039;AHbz&#039;
            set Slot[id] = 1
            set Cooldown[id][1] = 6.
            set Cooldown[id][2] = 6.
            set Cooldown[id][3] = 6.
        
            set id = &#039;AHwe&#039;
            set Slot[id] = 2
            set Cooldown[id][1] = 6.
            set Cooldown[id][2] = 6.
            set Cooldown[id][3] = 6.
        
            set HeroAbilities[&#039;Hamg&#039;][1] = &#039;AHbz&#039;
            set HeroAbilities[&#039;Hamg&#039;][2] = &#039;AHwe&#039;
            
            //Mountain King abilities
            set id = &#039;AHtb&#039;
            set Slot[id] = 1
            set Cooldown[id][1] = 6.
            set Cooldown[id][2] = 6.
            set Cooldown[id][3] = 6.
            
            set id = &#039;AHtc&#039;
            set Slot[id] = 2
            set Cooldown[id][1] = 6.
            set Cooldown[id][2] = 6.
            set Cooldown[id][3] = 6.
            
            set id = &#039;AHbh&#039;
            set Slot[id] = 3
            set Cooldown[id][1] = 0.
            set Cooldown[id][2] = 0.
            set Cooldown[id][3] = 0.
            
            set id = &#039;AHav&#039;
            set Slot[id] = 4
            set Cooldown[id][1] = 6.
            set Cooldown[id][2] = 6.
            set Cooldown[id][3] = 6.
            
            set HeroAbilities[&#039;Hmkg&#039;][1] = &#039;AHtb&#039;
            set HeroAbilities[&#039;Hmkg&#039;][2] = &#039;AHtc&#039;
            set HeroAbilities[&#039;Hmkg&#039;][3] = &#039;AHbh&#039;
            set HeroAbilities[&#039;Hmkg&#039;][4] = &#039;AHav&#039;
            
            
            //Warden skills
            set id = &#039;AEfk&#039;
            set Slot[id] = 1
            set Cooldown[id][1] = 15.
            set Cooldown[id][2] = 13.
            set Cooldown[id][3] = 11.
            
            set id = &#039;AEbl&#039;
            set Slot[id] = 2
            set Cooldown[id][1] = 10.
            set Cooldown[id][2] = 10.
            set Cooldown[id][3] = 1.
            
            set id = &#039;AEsh&#039;
            set Slot[id] = 3
            set Cooldown[id][1] = 30.
            set Cooldown[id][2] = 26.
            set Cooldown[id][3] = 22.
            
            set id = &#039;AEsv&#039;
            set Slot[id] = 4
            set Cooldown[id][1] = 60.
            
            set HeroAbilities[&#039;E000&#039;][1] = &#039;AEfk&#039;
            set HeroAbilities[&#039;E000&#039;][2] = &#039;AEbl&#039;
            set HeroAbilities[&#039;E000&#039;][3] = &#039;AEsh&#039;
            set HeroAbilities[&#039;E000&#039;][4] = &#039;AEsv&#039;
    endfunction

endlibrary


Thanks again kingkingyyk3!!

I think after some more optimization you could post this system.

PS: I changed some methods and added some
(the adding and removing wasn't accurate when checking level of ability, disabling works too)
 

kingkingyyk3

Visitor (Welcome to the Jungle, Baby!)
Reaction score
216
Glad to hear it. I'm getting mad because of finding out the bug. :banghead:
 

Nexor

...
Reaction score
74
There is only bug with mirror Image, but it doesn't matter.
I can't give you +rep :( must spread some :S
Please ask a mod to increase your rep by 10% :p

I can make now abilities that will affect your cooldown(s) :O
 

Nexor

...
Reaction score
74
I created some items that will affect the cooldown of the skills. I created structs based on your other structs, but now I need to setup the items like this:

JASS:
set Item_Mod[&#039;I000&#039;][0]     = -1
            set Item_Type[&#039;I000&#039;][0]    = 0.0


First question:
I don't want that [0] in the back, how should I write the structs so they don't need that thing?
Second question:
I want to have for the Item_Type[ability id] the type string, what should I do?

Here are the structs in the Cooldown library:

JASS:
struct Item_Type extends array
        private static hashtable ht = InitHashtable()
            
        static method operator [] takes integer id returns thistype
            return id
        endmethod
            
        method operator [] takes integer level returns real
            return LoadReal(thistype.ht,this,level)
        endmethod    
        
        method operator []= takes integer level, real value returns nothing
            call SaveReal(thistype.ht,this,level,value)
        endmethod 
        
    endstruct
    
    struct Item_Mod extends array
        private static hashtable ht = InitHashtable()
            
        static method operator [] takes integer id returns thistype
            return id
        endmethod
            
        method operator [] takes integer level returns real
            return LoadReal(thistype.ht,this,level)
        endmethod    
        
        method operator []= takes integer level, real value returns nothing
            call SaveReal(thistype.ht,this,level,value)
        endmethod    
        
    endstruct
 

Nexor

...
Reaction score
74
And for the other one? I want to save it too but it should be string.

EDIT: Okay I got it working, it was SaveStringBJ , I was trying SaveString
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top