WeakAuras

Custom function for power values?

  • 8 posts
    #1 May 07, 2011 at 01:37 UTC - 0 likes

    As an Arc mage, mana percentage is main concern. More specifically, percentage of mana excluding any temporary effects. As an example:

    • My max mana with raid buffs is roughly 100k.
    • When Power Torrent procs, I have an additional 525 int which translates into 7875 additional max mana.
    • If I was at 95% mana before the proc (95k), I am now at 88% mana.
    • If DMC:V also procs, then I get another 1680 int / 25200 mana, dropping me to 71% mana.
    • If only DMC:V procs, then my mana percentage is 76%.

    The problem here is that Arcane mages strive to hover their mana level at approximately 95% of max mana. When +int procs are active, we still want to hover at that value as if the proc were not even there - because once it fades anything over that 95% line is lost forever.

    What I would love to be able to do is provide a custom function that can check my active buffs for specific spells, and reduce my max mana value used in my aura by the amount temporarily buffing me. So when DMC:V is up, it would subtract that 25200 mana from the max that my character sheet shows for display purposes. This also has the side effect that my current mana value could occasionally exceed 100%, so the progress texture bar would obviously need to be able to cope with that.

    Is there any way to accomplish this?

    So far, the best I can think of is to set up a bunch of conditional auras that display my effective target percentage based on which procs are active. Something like this:

    DMC:V ActiveNoNoYesYes
    Power Torrent ActiveNoYesNoYes
    Displayed Target %95887671

    But the flaw is that as my gear improves, those numbers will change. I would much prefer the ability to alter the max mana value that is used in power auras to drive my standard HUD mana bar by providing a custom function.

    Thoughts?

    #2 May 07, 2011 at 04:19 UTC - 0 likes

    Well, first of all, I have no idea what a Progress Bar would do if you tried to set it beyond 100% capacity. It would probably just limit itself to 100%.

    Ignoring that, my first instinct would probably just be to set the maximum mana manually using a Custom Trigger. That would look something like this:

    Main Trigger: Custom - Status

    • Check On Event(s): UNIT_POWER
    • Custom Trigger:
      function()
        return true
      end
      
    • Custom Untrigger:
      function()
        return false
      end
      
    • Duration Info:
      function()
        return UnitPower("player"), 100000, function() return UnitPower("player"), 100000 end
      end
      

    This would give you a mana display that always maxes at 100,000 mana. But maybe that's not good enough, cause you want it to scale better with buffs, gear, etc. I think the thing to do, in that situation, is identify a time at which your current maximum mana value can reasonably be considered "base" and use that time to "lock in" the value. The first event that comes to mind is when you enter combat, which corresponds with the PLAYER_REGEN_DISABLED event. Thus, your updated display might look like this:

    Main Trigger: Custom - Status

    • Check On Event(s): UNIT_POWER, PLAYER_REGEN_DISABLED
    • Custom Trigger:
      function(event)
        if(event == "PLAYER_REGEN_DISABLED") then
          WA_BaseMaxMana = UnitPowerMax("player")
        end
        return true
      end
      
    • Custom Untrigger:
      function()
        return false
      end
      
    • Duration Info:
      function()
        return UnitPower("player"), (WA_BaseMaxMana or UnitPowerMax("player"), function() return UnitPower("player"), (WA_BaseMaxMana or UnitPowerMax("player") end
      end
      

    This is not a perfect solution, though, because if you are pre-potting with a Volcanic Potion, you might enter combat with an inflated maximum mana value. Perhaps we need a slightly more sophisticated trigger for when the base maximum mana is recorded. My proposal is, whenever you are not in combat and your current mana reaches your maximum mana (i.e., you drink to full mana). Here's a take on that:

    Main Trigger: Custom - Status

    • Check On Event(s): UNIT_POWER
    • Custom Trigger:
      function(event)
        if not(UnitAffectingCombat("player")) then
          if(UnitPower("player") == UnitPowerMax("player") then
            WA_BaseMaxMana = UnitPowerMax("player");
          end
        end
        return true
      end
      
    • Custom Untrigger:
      function()
        return false
      end
      
    • Duration Info:
      function()
        return UnitPower("player"), (WA_BaseMaxMana or UnitPowerMax("player"), function() return UnitPower("player"), (WA_BaseMaxMana or UnitPowerMax("player") end
      end
      

    This seems pretty robust to me. As long as you don't fail to drink to full mana before combat starts, your locked-in maximum mana should be accurate.


    P.S.: If you're familiar with Lua, you may notice that the Duration Info function returns, as its third argument, a function which returns the same first two arguments as the outer function. This is a cue to WeakAuras that your display should update its value as rapidly as possible; the third argument function is saved and used to obtain current values for the display on every frame update.

    If you're proficient with Lua and have a very keen eye, you might have realized that this is a horribly wasteful mechanism, because a new closure for the function will be created every time the outer Duration Info function is called, which wastes a lot of memory.

    As a result of this, the third argument for Duration Info function may be changed sometime before 1.4 as I try to eliminate memory leaks such as this.

    Last edited May 07, 2011 by Mirrormn
    #3 May 07, 2011 at 17:41 UTC - 0 likes

    @Mirrormn: Go

    This is getting close. I wrote a custom Duration Info function that produces exactly the values I want, and calculates by backing out the temporary mana buffs. It looks like this:

    function()
        function getBaseMaxMana()
            local function tempMana()
                local function check(name, power)
                    if UnitAura("player", name, "HELPFUL") == name then
                        return power;
                    else
                        return 0;
                    end
                end
                modifier = 0;
                modifier = modifier + check("Power Torrent", 7875);
                modifier = modifier + check("Volcanic Power", 18900);
                modifier = modifier + check("Volcanic Destruction", 25200);
                return modifier;
            end
            baseMax = UnitPowerMax("player") - tempMana();
            --print("Base Max Mana = "..baseMax);
            return baseMax;
        end
        
        return UnitPower("player"), getBaseMaxMana(), function() return UnitPower("player"), getBaseMaxMana() end
    end
    

    When I uncomment that print statement I can see the values in the chat window that confirm the calculation is perfect. However the progress texture is ignoring this new max value and shows the same position as a normal progress texture tied to Power.

    How do I convince this progress texture to use my calculated Duration Info? I must be missing something in the aura settings. Here is my exported aura string if you want to look at how I have it defined exactly:

    dmKfhaGiOQrbLofu5vuQQzbsDlkv2fLQmmr0XOOwgf4zGQMMOKRbkTnPs9nPQghLsoNOO3bQmpcfCpkuheeSqkOhsOOMiHsUOOqBKqvFKqrgjHcDscLALuYmjuXnPi7eK8trbdLczPukLNsLPkvCvkfBLqL(kLs1EL8xOObJomvTyOWJHyYa6YcBwu9zPkJwuQtd0RLkz2eYTby3K63sz4I0Yj55emDIUoK2oi03fHXdkopiA)QlZvNYbOCalhWQt5Gjd55cHSepSM7UV5mHVV5(gy2Sz47UYTR7UlhQwQa71luvNYHGkiBakxoQgrc20yXT1CQcjQspZ9IeITcnWswoPcSxVqvDkhQqGjQguwgwU0wIqjHmnkOswouHaZ0wIqjHmnkdlNeY0OCiOcYgGYHGkiBaWuczAuobPxIkuUaIHwkuoBGsS7GPrzW2ZOTbTnqj2DWec2yBqOCbedTSCg1seQYHkeyMgkKqltBjcvHr5qqfKnaIfQYlbB6YLJQrKGnnwCBnNZzoQgrc20ZEH0qVqyYdJjV2Jf3wZ5CoN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r5abwoiOqMM8AF5arA6cJYbzgYZfczjE762mS9nOFs4H1wW23G(9nOYTllylz5ekNYm8jlhelOmNvYKLSka
    
    #4 May 07, 2011 at 20:07 UTC - 0 likes

    Well, I wanted to avoid doing this by aura checking for a few reasons:

    • You will have to revise the display as you gain new trinkets, procs, etc.
    • Aura checking is not very efficient
    • You have to account for whether or not Blessing of Kings/Mark of the Wild is present

    However, it certainly can be done with aura checking. I've made quite a few changes to your function to improve efficiency (by removing the nest of functions), accounted for Blessing of Kings/Mark of the Wild, and limited the aura checking so it only updates when your maximum mana changes:

    function()
        local maxMana = UnitPowerMax("player")
        if(not WA_PreviousMaxMana or maxMana ~= WA_PreviousMaxMana) then
            WA_PreviousMaxMana = maxMana
            local tempMana = 0
            tempMana = tempMana + (UnitAura("player", "Power Torrent") and 7500 or 0)
            tempMana = tempMana + (UnitAura("player", "Volcanic Power") and 18000 or 0)
            tempMana = tempMana + (UnitAura("player", "Volcanic Destruction") and 24000 or 0)
            tempMana = tempMana + (UnitAura("player", "Lightweave") and 8700 or 0)
            tempMana = tempMana + (UnitAura("player", "Synapse Springs") and 7200 or 0)
            if(UnitAura("player", "Blessing of Kings") or UnitAura("player", "Mark of the Wild")) then
                tempMana = tempMana * 1.1
            else
                tempMana = tempMana * 1.05
            end
            
            WA_BaseMaxMana = maxMana - tempMana
        end
        
        WA_BaseMaxMana = WA_BaseMaxMana or maxMana
        
        return UnitPower("player"), WA_BaseMaxMana, function() return UnitPower("player"), WA_BaseMaxMana end
    end
    

    I also added some more procs for testing on my own Arcane Mage; you can remove those if they do not apply to you.

    I did not encounter the problem you mentioned where the graphical progress of the bar did not match properly with the new maximum values. When I tested your display, the bar would be at 100% any time my current mana was greater than or equal to the calculated base maximum mana.

    Last edited May 07, 2011 by Mirrormn
    #5 May 07, 2011 at 20:57 UTC - 0 likes

    This works exceptionally well.

    Thanks a bunch!

    #6 May 08, 2011 at 03:46 UTC - 0 likes

    I added some more to this, including a text value that calculates the value for display, and have it placed directly beneath a "normal" mana bar. Works great! This is what it looks like in action:

    For my custom Name Info, I am using the following function that I hope will not be too inefficient:

    function()
        local maxMana = WA_BaseMaxMana;
        if (not maxMana) then
            maxMana = UnitPowerMax("player");
        end
        local currMana = UnitPower("player");
        
        if (currMana > maxMana) then
            currMana = maxMana;
        end
        
        local perc = (currMana / maxMana) * 100.0;
        
        local formatted = string.format("%.1f", perc).."%%";
        
        return formatted;
    end
    

    The export link for the health bar + mana bar + arcane mana bar (if anyone cares) is:

    dKu6paGij5sQuyuqQtHiRIcsVcuuZIsPBPIyxsk(fbPAyGQJbWYiOEMkQPrbUMk02qf(MkvJdrX5Ou8ovknpvKY9GK2hOi5GqIfIk5HGIyIQivxKcQnsq8rkigjbjojbPSsc9sqrQzQIKUjfTtvWpruAOGslvfj8uuMkrCvevBLGK(kOWEj9xk0GvoSulgv0JrvtgqxMQnRs(SKQrJk1Pr41Qu0SjQBtj7gQFlXWHy5i9CqMUQUoqBxsPVtPA8ePZtG5RIeTFXkavIYGugfWz4kZszavgqvIYGC5lyle4xzCrwjsiR5PAyHirzeavMqXB5N7Sgdmd2IDNQmQxNOGLiaXvwDAberzUuKgd0bQCPVY4vj6baQeL9uI61DQkrzVaexzqF)GqkdXP8o(52B5NBJfeN2FHQSttzioL3Xp3El)CRmBoQmqi3iiM4vUugsXUtFbiUEaUYaXETo(vwd(fLbc5grCkVJFU9w(5w5uzGqUrKIDN(cqCLtLXdc9flJCta0v2ty5a1xzC2uysrUqvj6baQqUF2G7WnGmKb(zYWXDaCCwVo5ih6bH1da0dNvHC8ia4ctgo4aUW2ah(57gOxNC8O(ktU0avjkdeYnYl3qqkxkJxUHGujkdIaxx2vMjkgIHvMfO8tOsuMjkgIHvU0xF9vg1RtuWseG4kRbPnNnvzqFZFtiLtL9U0hK6kJzbcSURmbK96cYF9Wjam4OYiaQmHI3Yp3ktkzVUG8xfYraCChGnNVd4UWaaa4mh61jCWHYi4lyLtLbKacrUfiXL(NQF9kltzpHLtvo1xpiSkrz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YqJlFMvl1SXnPSNBhhXSSSSSSSmRwQzJ7muZiht8WwS7uZwk6ke5wGtRiDBeZYYYCmWiMLLLjx4B5mEqk1SXDgQzKJjEyl2Dk6ke5wGtRiDBeZYYYIywwwgXvgAEqk1SXDgmvMvl1SXnPSNBhhXSSSSSSSmEqk1SXDgQzwTuZg33gXSSSmhdmIzzzzrmllltUW3YzioLpd1m08GuQzJ7mHEMvl1SXnPmdndaC41a)2iMLLLfXSSSm5cFlNDvOw9)oWmuZGEkbUEnxfQv)ORUrnaUQSndXP8KQPMQBCJQBJywwwweZYYYO(dsXzxfQv)Vd82i6yGkJhe6lwk7ceZ)efmAsrmlJ6pifN9uqpIogOY8AD8dPmYpi0KyewYcddFkugp3o)nvMxRJFLXdc9flJVaexzqF)GqkdXP8o(rk2DQYS5OYqCkVJFKIDNASG40(luLDA6RmoBkmPixOQe9aavigC)8za2yGnWf2aBaC2GJ61jhpRhewpaVgYOhoRhaOVYKlnqvIYaHCJ8YneKYLYaHCJqioVYLY4LBiivIYGiW1LDLzIIHyy9vgeIZRsugebUUSRhaOV(kJ61jkyjcqCL1G0MZMQmOV5VjKYPYEclNQCQS3L(GuxzmlqG1DLrauzOq5ZmBCRmPK96cYFvihbWXDa2C(oG7cdaaGZCOxNWbhkJGVGvovMaYEDb5VkKt4aWX7cFh(5JK54DHVFhGEDIbh1xFLvREaGbWHRVQ
    
    #7 Jul 02, 2011 at 08:52 UTC - 0 likes

    Easirok, tyvm!

    I was looking for this.

    #8 Dec 06, 2012 at 19:23 UTC - 0 likes

    Fantastic. Almost exactly what i was looking for. Iv had a play with numbers but im not much of a coder and can't figure it out. Is there any way to make the bar show only between 80% and 100%. Really an arcane mage should never go below 90%, so a large amount of the blue bar is useless information. If it showed only 80-100% you could get much more clarity from a single glance.

    Thanks to everyone who contributed to this. Without coders we'd be sat in our own filth putting hammer to screw.

  • 8 posts

You must login to post a comment. Don't have an account? Register to get one!