Hello guys, I asked this in IRC and I intend to post the solution (if any) when it comes.
So I was doing a simple addon to track my buffs and I noticed that sometimes UnitAura returned nil values even when the buffs are up. It is more noticeable with frequent auras occurring. I have a sample code that worked in test. It's for warrior but you can change to any other aura.
Lua Code:
/run f = CreateFrame("Frame", nil, nil) f:RegisterEvent("UNIT_AURA", "player") f:SetScript("OnEvent", function(self, event, unit) print(AuraUtil.FindAuraByName("Overpower", unit)) end)
As I said, the more UNIT_AURA fires, the best you can see what I mean. Maybe I'm doing something wrong but I can't see where.
By the way, I'm posting the lua file that I noticed the problem.
Lua Code:
local TEXTURE = "Interface\\ChatFrame\\ChatFrameBackground"
local PIXEL = {
edgeFile = TEXTURE,
edgeSize = -1
}
-- Create simple StatusBar
local function CreateStatusBar(parent, name, width, height, minValue, maxValue, r, g, b)
local bar = CreateFrame("StatusBar", name, parent)
bar:SetStatusBarTexture(TEXTURE)
bar:SetBackdrop(PIXEL)
bar:SetBackdropBorderColor(0, 0, 0)
bar:SetStatusBarColor(r or 0, b or 1, g or 0)
bar:SetMinMaxValues(minValue, maxValue)
bar:SetWidth(width)
bar:SetHeight(height)
return bar
end
local function Warrior()
-- Overpower bars
local opEvent = CreateFrame("Frame", nil, nil)
local op1 = CreateStatusBar(PlayerFrame, "gwOp1", 10, 5, 0, 1, .5, .5, .5)
local op2 = CreateStatusBar(PlayerFrame, "gwOp2", 10, 5, 0, 1, .5, .5, .5)
op2:SetPoint("BOTTOMLEFT", PlayerFrame.healthbar, "TOPLEFT", 0, 1)
op1:SetPoint("LEFT", gwOp2, "RIGHT", 1, 0)
op1:SetMinMaxValues(0, 1)
op2:SetMinMaxValues(1, 2)
opEvent:RegisterEvent("UNIT_AURA", "player")
opEvent.startTime = 0
opEvent.endTime = 0
op1:SetValue(0)
op2:SetValue(0)
opEvent:SetScript("OnEvent", function(self, event, unit)
local name, _, stack, _, duration, endTime = AuraUtil.FindAuraByName("Overpower", unit)
if not endTime then
op1:SetValue(0)
op2:SetValue(0)
elseif opEvent.endTime ~= endTime then
op1:SetValue(stack)
op2:SetValue(stack)
opEvent.endTime = endTime
end
-- frame test: /run f = CreateFrame("Frame", nil, nil) f:RegisterEvent("UNIT_AURA", "player") f:SetScript("OnEvent", function(self, event, unit) print(AuraUtil.FindAuraByName("Overpower", unit)) end)
end)
end
-- Load auras
hooksecurefunc("PlayerFrame_ToPlayerArt", function(self)
Warrior()
end)
Solution:
LUA Code:
opEvent:RegisterUnitEvent("UNIT_AURA", "player")