1) Please use CODE tags around your code, not QUOTE tags. QUOTE tags do not preserve indentation, so it is unnecessarily hard to read your code.
2) Your code is currently creating a lot of global variables, which is bad.
3) Your code is currently running every time
anyone's auras change; since you only care about the player's auras, you should use RegisterUnitEvent with the "player" unit instead of just RegisterEvent.
4) Since you only care about a specific aura, you can just look for it directly, instead of looping over every aura on the player.
5) Here is your code, revised to show the texture only with more than 1 stack, and also to fix the problems listed above:
Code:
-- Get the localized spell name and store it in a variable:
local BACKDRAFT = GetSpellInfo(117828)
-- Create a frame to listen for events:
local f = CreateFrame("Frame")
-- Tell the frame to listen for the UNIT_AURA event
-- only when it fires for the player unit:
f:RegisterUnitEvent("UNIT_AURA", "player")
-- Tell the frame what to do when the event fires:
f:SetScript("OnEvent", function()
-- Get information about the Backdraft buff on the player:
local name, _, _, count = UnitBuff("player", BACKDRAFT)
-- Does the player have the buff with more than 1 stack?
if name and count > 1 then
-- Yes, they do! Show the overlay.
SpellActivationOverlay_ShowOverlay(SpellActivationOverlayFrame, 117828, "Textures\SpellActivationOverlays\Molten_Core", "LEFT", 1, 255, 255, 255, false, false)
else
-- No, they don't. Hide the overlay.
SpellActivationOverlay_HideOverlays(SpellActivationOverlayFrame, 117828)
end
end)
If you have other snippets doing similar things, I'd suggest revising them to match the above pattern; if you don't care about stacks, remove the "and count > 1" check. If you are looking for a debuff, change "UnitBuff" to "UnitDebuff".