Won't that depends on the situation? Some buffs might have different durations depending who casts them, their talents, glyphs, set bonuses, etc, so on a new application the "total duration" might not be the same as the last time you saw it.
Also, what's the relative frequency of COMBAT_LOG_EVENT_UNFILTERED events compared to UNIT_AURA or some other indication of (de)buff change?
the mod is for self casted aura's, basically talent procs. I want to see when my "surge of light" procs so i can get a free flash heal etc...
I've come up with a new way to calculate the expire time.
Instead of calling UnitBuff() to get the new expire time each OnShow() you can store the fixed "buff duration" for the specific buff the first time that Aura fires. Then you can calculate the expire time by GetTime() + auraDuration each time the "COMBAT_LOG_EVENT_UNFILTERED" fires for that Aura. Then OnUpdate() can just subtract GetTime() - expireTime to get timeLeft. This alleviates the need to constantly query UnitBuff every OnShow()
I'm pretty new to WoW API coding myself, but if I understand correctly, it can be problematic to try to use the "elapsed" argument that way. WoW's event dispatcher may give you the elapsed time since the last OnUpdate cycle *started*, but since you don't know how long each cycle *takes*, you can't just tally it up every time you get one and treat that as an accurate measure of time. The more OnUpdate code is running (anywhere, from any addon), the more extra processing time will be taken up per frame, and the more skew you'll get by summing that "elapsed" argument.
If you're tracking very short-term buffs that might not be noticeable, but I suspect if you ran the above on a several-minute buff you'd see your buff disappear while the timer was still ticking down.
The mod is basically watching for any talent abilities (Aura's/buffs not sure of the proper in-game term) that proc while in combat, such as "holy concentration" and "surge of light" (for priest) or "clear casting" and "missle barrage" for mage. It also makes sure the Aura is under 30 seconds, that way normal buffs won't pop up. I havent run into any problems with the duration countdown. But awesome advice guys, I'm going to play around with some of these examples.
I finally got some spare time to work on this mod. Here is how I ended up calculating the buff count down timer. Let me know if you guys have any suggestions to make it better :)
frame:SetScript("OnUpdate", function (self)
local auraName = self:GetName()
if GetTime() < AuraExpireTimes[auraName] then
frame:SetScript("OnShow", function (self)
local auraName = self:GetName()
AuraExpireTimes[auraName] = select(7,UnitBuff("player",auraName))
not 100% sure how auras work but wouldn't this be more efficient?
if frame:IsShown() then
for i, FM in ipairs(FrameManager) do
FM.expire = GetBuffExpire();
you the the table directly from the ipairs iterator so you don't have to table[i] it
personally instead of scanning all the auras each update i would only check the aura gain/loss events and check then if something proced (or the proc faded) and then you can setup your own timer or just watch that one aura if you need to keep track of its timer (if you can avoid OnUpdate you should (most of the time)
Yeah i am using ipairs, what I posted wasnt the acutal code, I'm at work hehe.
Anyway. Yeah I don't like using OnUpdate(). I've been thinking about it and here is what I want to do.
When an aura/buff proc's the mod generates a frame for it. I could have that frame run the OnShow(frame) event that calculates the expire time. Everytime the aura proc's the OnShow(frame) will be called, it will calculate until that frame is hidden. That way the OnUpdate() event isn't constantly scanning buffs. Totally inefficient lol.
The problem is, I'm not sure how to set a script to a dynamically generated frame.
if not frameName then
local frame = CreateFrame("Frame", frameName, "UIParent")
<set frame OnShow() script file here>