View Single Post
09-13-11, 06:38 PM   #5
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
The following will (theoretically) place a 60x60 icon in the center of your screen that is displayed only when you have a hostile target. When that target has the Flame Shock debuff, it will show the Earth Shock icon; otherwise it will show the Flame Shock icon.

Code:
local f = CreateFrame("Frame", "MySpellSuggestionFrame", UIParent)
f:SetWidth(60)
f:SetHeight(60)
f:SetPoint("CENTER")
f:Hide()

f.icon = f:CreateTexture(nil, "OVERLAY")
f:SetAllPoints(true)

f:RegisterEvent("PLAYER_TARGET_CHANGED")
f:SetScript("OnEvent", function(self, event, unit, ...)
    if event == "UNIT_AURA" then
        if unit ~= "target" then return end
        if UnitDebuff("target", "Flame Shock") then
            f.icon:SetTexture("Interface\\Icons\\Spell_Nature_EarthShock")
        else
            f.icon:SetTexture("Interface\\Icons\\Spell_Fire_FlameShock")
        end
   else
        -- Event must be PLAYER_TARGET_CHANGED
        -- since that's the only other event ever registered.
        if UnitCanAttack("player", "target") then
            self:RegisterEvent("UNIT_AURA")
            self:GetScript("OnEvent")(self, "UNIT_AURA", "target")
            self:Show()
        else
            self:Hide()
            self:UnregisterEvent("UNIT_AURA")
        end
    end
end)
As Seerah said, there is no way to make a clickable button, or key binding, that will cast one spell or the other depending on the target's debuffs. If you cannot do it with a macro (ignoring the macro length limit) you cannot do it with an addon.

In this case, I'd suggest setting up a macro that casts Flame Shock on shift-click/press, or Earth Shock otherwise; that's what I use on my shaman.
  Reply With Quote