WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Checking for specific buff/debuff on target? (https://www.wowinterface.com/forums/showthread.php?t=41405)

basketcase209 09-11-11 09:00 PM

Checking for specific buff/debuff on target?
 
I've been going crazy trying to figure this out, lol.
I've checked http://wowprogramming.com and http://www.wowwiki.com, but I'm sure that doing this is probably going to be complicated as the only relevant functions I've found are UnitAura, Unitbuff, UnitDebuff.
I've also checked out a few addons, but I'm having trouble decoding it.

I'm still quite fresh as far as lua script goes, so any tips or ideas would help.

brotherhobbes 09-11-11 10:16 PM

What are you trying to do with this once you've checked for a specific buff/debuff?

All three of those functions will return nil if the buff/debuff you are looking for is not found on the specified unit. Example:

if UnitAura("player", "buff name") then etc etc

basketcase209 09-11-11 10:57 PM

The solution was simple... no wonder it took me so long to figure out, lol.

I'm mostly just playing with it to try to learn how to write basic addons so I can move up to more complex ones later on.
I was trying to write an addon that adds a button that checks to see if the target has Flame Shock on, and if it does it'll cast Earth Shock instead.
I figured it'd be a good place to start as far as learning goes.

Seerah 09-12-11 10:12 PM

Well, your button cannot have that smart logic to know what spell to cast. But it can tell *you* to cast Earth Shock instead.

Phanx 09-13-11 06:38 PM

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.

basketcase209 09-18-11 11:25 AM

Thanks for the tips. =)


All times are GMT -6. The time now is 06:51 AM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI