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 The Helper:
    The bots will show up as users online in the forum software but they do not show up in my stats tracking. I am sure there are bots in the stats but the way alot of the bots treat the site do not show up on the stats
  • Varine Varine:
    I want to build a filtration system for my 3d printer, and that shit is so much more complicated than I thought it would be
  • Varine Varine:
    Apparently ABS emits styrene particulates which can be like .2 micrometers, which idk if the VOC detectors I have can even catch that
  • Varine Varine:
    Anyway I need to get some of those sensors and two air pressure sensors installed before an after the filters, which I need to figure out how to calculate the necessary pressure for and I have yet to find anything that tells me how to actually do that, just the cfm ratings
  • Varine Varine:
    And then I have to set up an arduino board to read those sensors, which I also don't know very much about but I have a whole bunch of crash course things for that
  • Varine Varine:
    These sensors are also a lot more than I thought they would be. Like 5 to 10 each, idk why but I assumed they would be like 2 dollars
  • Varine Varine:
    Another issue I'm learning is that a lot of the air quality sensors don't work at very high ambient temperatures. I'm planning on heating this enclosure to like 60C or so, and that's the upper limit of their functionality
  • Varine Varine:
    Although I don't know if I need to actually actively heat it or just let the plate and hotend bring the ambient temp to whatever it will, but even then I need to figure out an exfiltration for hot air. I think I kind of know what to do but it's still fucking confusing
  • The Helper The Helper:
    Maybe you could find some of that information from AC tech - like how they detect freon and such
  • Varine Varine:
    That's mostly what I've been looking at
  • Varine Varine:
    I don't think I'm dealing with quite the same pressures though, at the very least its a significantly smaller system. For the time being I'm just going to put together a quick scrubby box though and hope it works good enough to not make my house toxic
  • Varine Varine:
    I mean I don't use this enough to pose any significant danger I don't think, but I would still rather not be throwing styrene all over the air
  • The Helper The Helper:
    New dessert added to recipes Southern Pecan Praline Cake https://www.thehelper.net/threads/recipe-southern-pecan-praline-cake.193555/
  • The Helper The Helper:
    Another bot invasion 493 members online most of them bots that do not show up on stats
  • Varine Varine:
    I'm looking at a solid 378 guests, but 3 members. Of which two are me and VSNES. The third is unlisted, which makes me think its a ghost.
    +1
  • The Helper The Helper:
    Some members choose invisibility mode
    +1
  • The Helper The Helper:
    I bitch about Xenforo sometimes but it really is full featured you just have to really know what you are doing to get the most out of it.
  • The Helper The Helper:
    It is just not easy to fix styles and customize but it definitely can be done
  • The Helper The Helper:
    I do know this - xenforo dropped the ball by not keeping the vbulletin reputation comments as a feature. The loss of the Reputation comments data when we switched to Xenforo really was the death knell for the site when it came to all the users that left. I know I missed it so much and I got way less interested in the site when that feature was gone and I run the site.
  • Blackveiled Blackveiled:
    People love rep, lol
    +1
  • The Helper The Helper:
    The recipe today is Sloppy Joe Casserole - one of my faves LOL https://www.thehelper.net/threads/sloppy-joe-casserole-with-manwich.193585/
  • The Helper The Helper:
    Decided to put up a healthier type recipe to mix it up - Honey Garlic Shrimp Stir-Fry https://www.thehelper.net/threads/recipe-honey-garlic-shrimp-stir-fry.193595/
  • The Helper The Helper:
    Here is another comfort food favorite - Million Dollar Casserole - https://www.thehelper.net/threads/recipe-million-dollar-casserole.193614/

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top