Cooldown system issues

kingkingyyk3

Visitor (Welcome to the Jungle, Baby!)
Reaction score
216
Updated my post. Now it can handle multiple level.

Usage :
JASS:
set Slot['TEST'] = 1
set Cooldown['TEST'][<level>] = 10.
set HeroAbilities['HERO'][<slot number>] = 'TEST'
 

Nexor

...
Reaction score
74
Kingkingyyk3: Your updated post has some compile errors, and I don't know your code, so I can't repair it.

Viikuna: The compiler says at this line

JASS:
private static method hook_ReplaceUnitBJ takes unit whichUnit, integer newUnitId, integer unitStateMethod returns nothing


the following: Unable to find textmacro : "optional"
This has never happened to me.

And yes, I have the latest NewGen I dl'ed it yesterday.
 

kingkingyyk3

Visitor (Welcome to the Jungle, Baby!)
Reaction score
216
Kingkingyyk3: Your updated post has some compile errors, and I don't know your code, so I can't repair it.

Updated again. 100% compilable now.
 

Nexor

...
Reaction score
74
yeah, it compiles now, but it won't give any fake ability to the caster and will not give the ability back.

other issue: using mirror image caused critical error
 

kingkingyyk3

Visitor (Welcome to the Jungle, Baby!)
Reaction score
216
Sorry, my bad. >< Nevermind, it should works now. Newer version is in my previous post.

Here's an example for implementing cooldown system for normal Archmage :
JASS:
library CooldownInit initializer Init requires Cooldown

    private function Init takes nothing returns nothing
        set Slot[&#039;AHbz&#039;] = 1
        set Cooldown[&#039;AHbz&#039;][1] = 6.
        set Cooldown[&#039;AHbz&#039;][2] = 6.
        set Cooldown[&#039;AHbz&#039;][3] = 6.
        
        set Slot[&#039;AHwe&#039;] = 2
        set Cooldown[&#039;AHwe&#039;][1] = 20.
        set Cooldown[&#039;AHwe&#039;][2] = 20.
        set Cooldown[&#039;AHwe&#039;][3] = 20.
        
        set HeroAbilities[&#039;Hamg&#039;][1] = &#039;AHbz&#039;
        set HeroAbilities[&#039;Hamg&#039;][2] = &#039;AHwe&#039;
        
    endfunction
    
endlibrary

Or you can do it in spell's init if the spell is triggered.
 

Nexor

...
Reaction score
74
Thank you for a demo setup.

I tried it out and it isn't working :S:S

The other thing, with the mirror image ability: it just exits with a critical error.
I don't think the END_CAST event is the best for this system :S

EDIT: sorry, I didn't see you updated the system code.
It's working woohooo :D:D thank you very much.

Some questions though:
-how do I implent some functions, like:
*the remaining time of an ability
*name of the ability and such
-how do I implent functions that will manipulate with the ability cooldown:
*increase/decrease
*set it to a number
*pause it !!!
*reset
*restart
 

kingkingyyk3

Visitor (Welcome to the Jungle, Baby!)
Reaction score
216
I will implement them. Just wait for the update. :)

JASS:
library Cooldown initializer Init requires PUI, ABC
    
    globals
        private constant integer MAX_ABILITY = 4
        private integer array DisabledAbilities
        private constant integer MaxAbilityPlusOne = MAX_ABILITY + 1
    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]
        
        method reset takes integer pos returns nothing
            set .ready[pos] = true
            call PauseTimer(.t[pos])
            call UnitRemoveAbility(.hero,DisabledAbilities[pos])
            call UnitAddAbility(.hero,HeroAbilities[GetUnitTypeId(.hero)][pos])
        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 = 0
            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 lv = GetUnitAbilityLevel(.hero,abil_id)
            call UnitRemoveAbility(.hero,abil_id)
            call UnitAddAbility(.hero,DisabledAbilities[pos])
            call TimerStart(.t[pos],Cooldown[abil_id][lv],false,function thistype.removeCooldown)
            //call BJDebugMsg(&quot;Slot : &quot; + I2S(pos))
            //call BJDebugMsg(&quot;Cooldown : &quot; + R2S(Cooldown[abil_id][lv]))
        endmethod
        
        method resetall takes nothing returns nothing
            local integer i = 1
            loop
                call .reset(i)
            exitwhen i == MAX_ABILITY
            endloop
        endmethod
        
        method remaining takes integer abil_id returns real
            return TimerGetRemaining(.t[Slot[abil_id]])
        endmethod
        
        method pause takes integer abil_id returns nothing
            call PauseTimer(.t[Slot[abil_id]])
        endmethod
        
        method restart takes integer abil_id returns nothing
            local integer i = Slot[abil_id]
            call .reset(i)
            call .add(abil_id)
        endmethod
        
        method isReady takes integer abil_id returns boolean
            return .ready[Slot[abil_id]]
        endmethod
        
        static method create takes unit hero returns thistype
            local thistype this = thistype.allocate()
            set .hero = hero
            return this
        endmethod
        //! runtextmacro PUI()
    endstruct
    
    private function Cond takes nothing returns boolean
        if Data[GetTriggerUnit()] == 0 then
            set Data[GetTriggerUnit()] = Data.create(GetTriggerUnit())
        endif
        call Data(Data[GetTriggerUnit()]).add(GetSpellAbilityId())
        return false
    endfunction
    
    private function Init takes nothing returns nothing
        local trigger trig = CreateTrigger()
        call TriggerRegisterAnyUnitEventBJ(trig,EVENT_PLAYER_UNIT_SPELL_ENDCAST)
        call TriggerAddCondition(trig,Condition(function Cond))
        
        set DisabledAbilities[1] = &#039;A001&#039;
        set DisabledAbilities[2] = &#039;A002&#039;
        set DisabledAbilities[3] = &#039;A003&#039;
        set DisabledAbilities[4] = &#039;A004&#039;
    endfunction
    
endlibrary


JASS:
call Cooldown_Data(hero).reset(ability&#039;s id)
call Cooldown_Data(hero).resetAll()
Cooldown_Data(hero).remaining(ability&#039;s id) -&gt; remaining cooldown
call Cooldown_Data(hero).pause(ability&#039;s id)
call Cooldown_Data(hero).resume(ability&#039;s id)
call Cooldown_Data(hero).restart(ability&#039;s id)
Cooldown_Data(hero).isReady(ability&#039;s id) -&gt; Is the ability ready?
//For abilities&#039; name, just use
GetObjectName(ability&#039;s id) -&gt; string
 

Nexor

...
Reaction score
74
Hmm it looks nice :) Thank you !

Q: Is it possible to write in the argument the skill position and not the ability id ?
 

Nexor

...
Reaction score
74
Okay, I got the position part I asked for in my previous post.

Now I want to write out the cooldowns locally for each player in a multiboard.
But it seems the values got overwritten and I don't know the reason.
 

kingkingyyk3

Visitor (Welcome to the Jungle, Baby!)
Reaction score
216
Is it possible to write in the argument the skill position and not the ability id
Just use Slot[ability] to convert ability into slot.

Now I want to write out the cooldowns locally for each player in a multiboard.
Mind to post the map? :)
 

kingkingyyk3

Visitor (Welcome to the Jungle, Baby!)
Reaction score
216
You have messed up your multiboard.
Just use 0 as array value, it works flawlessly. It can reduce some calculating.
 

Nexor

...
Reaction score
74
I don't get it where should I use 0 as array value, in the multiboard update trigger?
 

Nexor

...
Reaction score
74
I changed it, and now it shows for me (player 0) the values of player 1

Could you change it in the posted map and send it back?
 

Nexor

...
Reaction score
74
For me, the PUI writes out some error ALOT of times (because the periodic trigger)
And if I don't cast the spell first (I wait until comp player casts it) then I can see his cooldown
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      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