1. #1
    Deleted

    WeakAuras2 custom progress

    --- SOLVED ---
    Thank you so much pnutbutter for the example code and thanks to the people at #wowuidev that helped me understand variable scopes.

    For anyone that wants something similar this is the code I ended up with:
    Code:
    function()
        local myBuff="Recklessness"
        local myCd=myBuff
        
        if not WA_Kapten_lostTime then
            WA_Kapten_lostTime = {}
        end
        local buffDur,buffExpTime=select(6,UnitBuff("player",myBuff))
        if buffDur then
            WA_Kapten_lostTime[myBuff] = GetTime()
            return buffDur,buffExpTime
        else
            local cdStartTime,cdDur=GetSpellCooldown(myCd)
            if cdDur>0 then
                local delta = WA_Kapten_lostTime[myBuff] - cdStartTime
                return cdDur-delta,cdStartTime+cdDur,nil,true
            end
        end
        return 0,0
    end
    --- ORIGINAL ---
    I've been searching and tearing my hair out, there is no good WA2 wiki/documentation as I am trying to learn this useful tool.
    I've watched Colin S's videos and I've learned a lot and want to take my auras to the next level.

    I am trying to figure out how to make a completely custom progress bar. But I have no Idea how to set the progress.
    I'm trying to create a bar that depletes with the buff and then refills with the cool down, I've manged to do this with two auras thanks to Colin S's video about trinkets but would like to make it in too one more reliable aura.

    Any guidance, help or examples would really be appreciated.
    Last edited by mmoc4c2a2e02d6; 2014-05-12 at 10:58 AM. Reason: Solved

  2. #2
    Are you talking about an actual custom .LUA bar or one that you can make from the presets in the addon

  3. #3
    Deleted
    I cant figure out how to set the progress with Lua or how to calculate the time remaining

  4. #4
    Well I cant really help you with the coding. Im no LUA expert like Colin is. Quick fix would be to make two different progress bars to track the spell cooldown progress

  5. #5
    Deleted
    Yeah I've already done that but would like to move away from that solution since it clutters down the options menu and I would really really love to know how to make custom progress bars.

  6. #6
    Quote Originally Posted by ImHitch View Post
    But I have no Idea how to set the progress.
    I'm trying to create a bar that depletes with the buff and then refills with the cool down.
    duration function
    Code:
    function()
        local buffDur,buffExpTime=select(6,UnitBuff("player",myBuff))
        if buffDur then
            return buffDur,buffExpTime
        else
            local cdStartTime,cdDur=GetSpellCooldown(myCd)
            if cdDur>0 then
                return cdDur,cdStartTime+cdDur,nil,true
            end
        end
        return 0,0
    end
    the 4th return value indicates whether the progress should be inverted.


    also, keep in mind you probably don't actually want to call the API functions in your duration function, but you can if you don't care about performance. It's just for example here
    Last edited by pnutbutter; 2014-05-11 at 11:52 PM.

  7. #7
    Deleted
    Quote Originally Posted by pnutbutter View Post
    duration function
    Code:
    function()
        local buffDur,buffExpTime=select(6,UnitBuff("player",myBuff))
        if buffDur then
            return buffDur,buffExpTime
        else
            local cdStartTime,cdDur=GetSpellCooldown(myCd)
            if cdDur>0 then
                return cdDur,cdStartTime+cdDur,nil,true
            end
        end
        return 0,0
    end
    the 4th return value indicates whether the progress should be inverted.


    also, keep in mind you probably don't actually want to call the API functions in your duration function, but you can if you don't care about performance. It's just for example here
    Thank you so much for the example, whats the third return?

    - - - Updated - - -

    Code:
    function()
        local myBuff="Berserker Rage"
        local myCd=myBuff
        local loseTime = loseTime or 0
        
        local buffDur,buffExpTime=select(6,UnitBuff("player",myBuff))
        print((buffDur or "nil")..", "..(loseTime or "nil"))
        if buffDur then
            loseTime = GetTime()
            return buffDur,buffExpTime
        else
            local cdStartTime,cdDur=GetSpellCooldown(myCd)
            if cdDur>0 then
                local time = GetTime()
                local delta = time-loseTime
                return cdDur-delta,cdStartTime+cdDur,nil,true
            end
        end
        return 0,0
    end
    Im trying to make the CD start when you lose the buff and offset by the duration used but the variable loseTime is always 0, why is that? I've set it to update when you have the buff and to be 0 or itself so I wont get nil errors or lose the variable. Its a local but the if case should be able to change its value.
    Last edited by mmoc4c2a2e02d6; 2014-05-12 at 09:48 AM. Reason: fixed delta variable

  8. #8
    Quote Originally Posted by ImHitch View Post
    Thank you so much for the example, whats the third return?
    "static": determines what happens to the progress in the aura's OnUpdate function:
    if it's false or nil, the progress is treated as a normal duration -- it decays/grows at the same rate as time passes. This is generally what you want for auras, cooldowns, etc.
    if it's a function, the progress is updated by this function. The function needs to return the instantaneous static value for any given frame. This is if you really need to be advanced.
    if it's a string, the progress is updated by the duration function itself every frame, but the values returned by the function are always considered static.
    otherwise, the progress is treated as static -- it doesn't change at all over time, usually used for things like health. In this case the first two returns are currentValue and maxValue, instead of duration and expirationTime.
    - - - Updated - - -
    Im trying to make the CD start when you lose the buff and offset by the duration used but the variable loseTime is always 0, why is that? I've set it to update when you have the buff and to be 0 or itself so I wont get nil errors or lose the variable. Its a local but the if case should be able to change its value.
    Maybe you're misunderstanding scope? When you do
    Code:
    local loseTime =  --whatever
    you're declaring loseTime as a new variable in that scope. As soon as the function terminates, the variable becomes garbage, and the next pass through the function, it becomes a new variable again. If you want its value to persist between executions of the function, you need to declare it outside the function (not possible with Weakauras framework) or get rid of the "local" to use it as a global variable. This is what's happening now:
    Code:
    local loseTime = loseTime  or 0
    --same as:
    --local loseTime = nil or 0
    
    if buffDur then
        loseTime = GetTime()
        return buffDur,buffExpTime 
        --loseTime becomes garbage
    else

  9. #9
    hello there, have a lil question about progress bar.
    i have my progress bar for Ancestral Vigor viewed on me, but i cant understand, how to make it do not calculate this buff.

    example:
    i have 400k hp, buff gives me 40k more, and my bar grows up for this 10% and max bar now 440k. How i can calculate w/o this buff?

    sorry for my bad english:

    here my code for that progress bar:
    Code:
    function ()
        local name,_,icon,_,_,_,_,_,_,_,_,_,_,_,value=UnitBuff("player", "Ancestral Vigor")
        if not value then
            value = 0
        end
        local maxValue = UnitHealthMax("player")*0.10
        return value, maxValue, true
        
    end
    i need to get maxValue w/o buff Ancestral Vigor, how i must to do this.

    sorry for my bad english.
    Last edited by Rusangel; 2014-05-13 at 04:24 PM.

  10. #10
    up, any1 can help me ?

  11. #11
    Quote Originally Posted by Rusangel View Post
    hello there, have a lil question about progress bar.
    i have my progress bar for Ancestral Vigor viewed on me, but i cant understand, how to make it do not calculate this buff.

    example:
    i have 400k hp, buff gives me 40k more, and my bar grows up for this 10% and max bar now 440k. How i can calculate w/o this buff?

    sorry for my bad english:

    here my code for that progress bar:
    Code:
    function ()
        local name,_,icon,_,_,_,_,_,_,_,_,_,_,_,value=UnitBuff("player", "Ancestral Vigor")
        if not value then
            value = 0
        end
        local maxValue = (UnitHealthMax("player")-value)*0.10
        return value, maxValue, true
        
    end
    i need to get maxValue w/o buff Ancestral Vigor, how i must to do this.

    sorry for my bad english.
    I probably misunderstood the question but it seems like you could fix it by just changing the part I put in bold^

    Also, make your own thread next time
    Last edited by pnutbutter; 2014-05-16 at 08:35 PM.

  12. #12
    Quote Originally Posted by pnutbutter View Post
    I probably misunderstood the question but it seems like you could fix it by just changing the part I put in bold^

    Also, make your own thread next time

    thx alot - this works fine!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •