Thread Tools Display Modes
09-11-11, 09:00 PM   #1
basketcase209
A Defias Bandit
Join Date: Sep 2011
Posts: 3
Smile 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.
  Reply With Quote
09-11-11, 10:16 PM   #2
brotherhobbes
A Rage Talon Dragon Guard
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 313
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
  Reply With Quote
09-11-11, 10:57 PM   #3
basketcase209
A Defias Bandit
Join Date: Sep 2011
Posts: 3
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.
  Reply With Quote
09-12-11, 10:12 PM   #4
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
Well, your button cannot have that smart logic to know what spell to cast. But it can tell *you* to cast Earth Shock instead.
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
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
09-18-11, 11:25 AM   #6
basketcase209
A Defias Bandit
Join Date: Sep 2011
Posts: 3
Thanks for the tips. =)
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Checking for specific buff/debuff on target?

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off