• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[vJASS] Timer bugs when it shouldnt.

Status
Not open for further replies.
Hi, I have a library that I made, that counts stacks on a hero. I use a function called AddFreudeStack which takes an ability id and a unit to add a stack to a unit. When the unit reaches 10 stacks, it resets the cooldown of the spell that I used to call the function. Additionally, the unit gets double agility for 15 seconds. Now, everything works as it should, except for one thing: sometimes the Agility doesnt return to normal. It does decrease, but not all the way back to the original amount, and I have no idea why. So I'm posting here for some help.

JASS:
library FearStacks requires TimerUtils
    globals
        integer array FearCounter
        integer array FearCountExtra
        integer array FearStacking
        constant integer Schadenfreude_BUFF_ID = 'A0CJ'
        constant integer Schadenfreude_UNIT_ID = 'U004'
        constant string Schadenfreude_EFFECT = "war3mapImported\\Grin Curse.mdx"
        constant string Schadenfreude_ATTACH = "chest"
    endglobals

    struct Schadenfreude
        unit u
        integer i
        method destroy takes nothing returns nothing
            set this.u = null
        endmethod
    endstruct
    
    //native UnitAlive takes unit id returns boolean

    function Schadenfreude_Handler takes nothing returns nothing
        local timer t = GetExpiredTimer()
        local Schadenfreude data = GetTimerData(t)
        local integer ud = GetUnitUserData(data.u)

        if GetUnitTypeId(LC[(1 + GetPlayerId(GetOwningPlayer(data.u)))]) != Schadenfreude_UNIT_ID or LC[(1 + GetPlayerId(GetOwningPlayer(data.u)))] != data.u then
        else
            if FearCountExtra[ud] > 0 then
                set FearCountExtra[ud] = FearCountExtra[ud] - 1
            else
                set FearCounter[ud] = FearCounter[ud] - 1
            endif
        endif
    
        call data.destroy()
        call ReleaseTimer(GetExpiredTimer())
    
    
        set t = null
    endfunction
    

    function Schadenfreude_Handler2 takes nothing returns nothing
        local timer t = GetExpiredTimer()
        local Schadenfreude data = GetTimerData(t)
        local integer ud = GetUnitUserData(data.u)
    
        set FearStacking[ud] = FearStacking[ud] - 1
    
        if FearStacking[ud] == 0 then
            call SetUnitVertexColor(data.u, 190, 190, 190, 255)
            call UnitRemoveAbility(data.u, Schadenfreude_BUFF_ID)
        endif
    
        call SetHeroAgi(data.u, GetHeroAgi(data.u, true) - data.i, true)
    
        call data.destroy()
        call ReleaseTimer(t)
    
        set t = null
    endfunction
    
    function AddFreudeStack takes integer id, unit cast returns nothing
        local timer t
        local Schadenfreude data
        local unit u = cast
        local integer i
        local integer ud = GetUnitUserData(u)
        local texttag tt
        local string text
    
        if FearCounter[ud] == 9 then
            set FearCountExtra[ud] = FearCountExtra[ud] + 9
            set FearCounter[ud] = 0

            set data = Schadenfreude.create()
            set data.u = u
            set data.i = GetHeroAgi(data.u, true)
        
            set tt = CreateTextTag()
            set text = "|cFF4A484AE|r|cFF4A454Cn|r|cFF4B414Fd|r|cFF4B3E52u|r|cFF4C3B54r|r|cFF4C3856i|r|cFF4D3459n|r|cFF4D315Cg|r|cFF4E2E5E |r|cFF4E2B60M|r|cFF4F2763a|r|cFF4F2466l|r|cFF4F2168i|r|cFF501D6Ac|r|cFF501A6De|r|cFF511770 |r|cFF511472L|r|cFF521074e|r|cFF520D77v|r|cFF530A7Ae|r|cFF53077Cl|r|cFF54037E |r|cFF54008110"
    
            call SetTextTagText(tt, text, .024)
            call SetTextTagPos(tt, GetUnitX(cast), GetUnitY(cast), 0.0)
            call SetTextTagColor(tt, 255, 255, 255, 255)
            call SetTextTagVelocity(tt, GetRandomReal( -.02, .02), GetRandomReal( -.02, .02))
            call SetTextTagVisibility(tt, true)
            call SetTextTagFadepoint(tt, 2.0)
            call SetTextTagLifespan(tt, 5.0)
            call SetTextTagPermanent(tt, false)
        
            call SetHeroAgi(data.u, GetHeroAgi(data.u, true) + data.i, true)
            call UnitAddAbility(data.u, Schadenfreude_BUFF_ID)
            call SetUnitVertexColor(data.u, 51, 0, 51, 128)
            call DestroyEffect(AddSpecialEffectTarget(Schadenfreude_EFFECT, data.u, Schadenfreude_ATTACH))
            set FearStacking[ud] = FearStacking[ud] + 1
        
            set t = NewTimer()
            call SetTimerData(t, data)
            call TimerStart(t, 15., false, function Schadenfreude_Handler2)
        
            set i = GetUnitAbilityLevel(u, id)
            call UnitRemoveAbility(u, id)
            call UnitAddAbility(u, id)
            call SetUnitAbilityLevel(u, id, i)
        else
        
            set FearCounter[ud] = FearCounter[ud] + 1
            set tt = CreateTextTag()
            set text = "|cFF4A484AE|r|cFF4A454Cn|r|cFF4B414Fd|r|cFF4B3E52u|r|cFF4C3B54r|r|cFF4C3856i|r|cFF4D3459n|r|cFF4D315Cg|r|cFF4E2E5E |r|cFF4E2B60M|r|cFF4F2763a|r|cFF4F2466l|r|cFF4F2168i|r|cFF501D6Ac|r|cFF501A6De|r|cFF511770 |r|cFF511472L|r|cFF521074e|r|cFF520D77v|r|cFF530A7Ae|r|cFF53077Cl|r|cFF54037E |r|cFF540081" + I2S(FearCounter[ud])
    
            call SetTextTagText(tt, text, .024)
            call SetTextTagPos(tt, GetUnitX(cast), GetUnitY(cast), 0.0)
            call SetTextTagColor(tt, 255, 255, 255, 255)
            call SetTextTagVelocity(tt, GetRandomReal( -.02, .02), GetRandomReal( -.02, .02))
            call SetTextTagVisibility(tt, true)
            call SetTextTagFadepoint(tt, 2.0)
            call SetTextTagLifespan(tt, 5.0)
            call SetTextTagPermanent(tt, false)

            set t = NewTimer()
            set data = Schadenfreude.create()
            set data.u = u
            call SetTimerData(t, data)
            if id == 'A0CU' then
                call TimerStart(t, 30., false, function Schadenfreude_Handler)
            elseif id == 'A0CK' then
                call TimerStart(t, 5., false, function Schadenfreude_Handler)
            else
                call TimerStart(t, 10., false, function Schadenfreude_Handler)
            endif
        endif
    
        set text = null
        set tt = null
        set t = null
        set u = null
    endfunction
    
endlibrary
 
Oops. Apparently I can't read.

Do you have a test map that I can check? The best option would be to display a debug message when the agility is reduced, to verify whether the correct amount of agility is being removed:
JASS:
call BJDebugMsg(I2S(data.i))

If it does show the correct value, then it may be something external. If it displays the wrong value, then it is likely an issue with the code.

Also, how far off is it? Just by 1 or 2? Or is it off by more than that?
 
Sure I have a test map, I attached it to my post. (You need newgen 5d with UMSWE enabled).

Well the amount that it's off by varies greatly, sometimes it's off by 1 or 2, sometimes it's off by 10, sometimes by thousands...

Edit: I figured out the problem, it was because when I set the agility I did GetHeroAgi(u,true), which means i was adding all the green agility numbers, which would not properly get removed later.

Thanks for help purgeandfire!
 
Last edited:
Status
Not open for further replies.
Top