Originally Posted by
sintrigue
Hello,
I am extremely new to LUA and have worked on this for about five hours now. My code, below, fires when any buff starts or stops. I only want it to fire when the buff listed (in this case, rogue's Feint) completes.
Code:
local frame = CreateFrame("Frame")
local _, _, _, _, _, _, expirationTime = UnitAura("player", "Feint");
frame:RegisterEvent("UNIT_AURA")
frame:SetScript("OnEvent", function()
if (expirationTime==nil) then
print("Feint is ready!");
end
end)
Seems like it should be simple, but I'm knocking my head around this and am getting nowhere. Any help would be appreciated.
Thanks,
--S
Another obvious bug here is that you only read the 'expirationTime' once, and that's when the addon starts. Meaning your function will ALWAYS fire, everytime something about any player's aura fires. Regardless of whether or not you're using unit events or "normal" ones, this bug will cause it to be wrong no matter what happens!
Also, by using the name of the aura in UnitAura, this will only work for English gaming clients. I would suggest using spellIDs instead, as these will work for all clients, in all regions of the world.
This is what I would have done. Might be some typos, as I didn't test it. But anyway:
Code:
local has_feint -- we will use this to track when Feint is active
local feint_spellID = 1966 -- spellID of Feint, according to Wowhead
local frame = CreateFrame("Frame")
frame:RegisterEvent("UNIT_AURA")
frame:SetScript("OnEvent", function(self, event, ...)
-- If we don't use unit events, but the general one,
-- we can still see what unit the event is firing for by
-- checking the first argument passed to the event function!
local unit = ...
if unit ~= "player" then
return
end
local found_feint -- whether or not we'll find it in the loop below
-- search through all auras for Feint
for i = 1,40 do
local spellID = select(11, UnitAura("player",i))
if spellID == feint_spellID then
found_feint = true -- set our local flag to indicate we found it
break -- exit the loop if it's found
end
end
-- if we found Feint on the player, set the variable that tracks it to true
if found_feint and not has_feint then
has_feint = true
end
-- if our variable says we have Feint, but we didn't find it this time,
-- that means the Feint buff has run out, and it's time to use the ability again!
if has_feint and not found_feint then
print("Feint is ready!")
has_feint = false
end
end)