Thread Tools Display Modes
01-06-13, 03:41 AM   #1
mchwxj
A Fallenroot Satyr
Join Date: Jan 2013
Posts: 20
Need help of LUA Code: Buff Monitor (Like Power Aura)

The following code is what i use to indicate buffs, same effect as Power Aura. Could anyone help me modify it? I want it to show Texture only when specified buff stacks more than 1 time. Thanks a lot Hope my English works. haha

PSF=CreateFrame("FRAME")
PSF:RegisterEvent("UNIT_AURA");
PSF:SetScript('OnEvent',function()

o=0
for i=1,40 do
_,_,_,_,_,_,_,_,_,_,id=UnitAura("Player",i)
if id==117828 then SpellActivationOverlay_ShowOverlay

(SpellActivationOverlayFrame,117828,"TEXTURES\\SPELLACTIVATIONOVERLAYS\\molten_core.

BLP","LEFT",1,255,255,255,false,false)
o=1
end
end
if o==0 then SpellActivationOverlay_HideOverlays(SpellActivationOverlayFrame,117828)
end
end)
  Reply With Quote
01-06-13, 10:55 PM   #2
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
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".
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
01-07-13, 02:25 AM   #3
Vlad
A Molten Giant
 
Vlad's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2005
Posts: 793
Here is your re-revised code:
Code:
-- spellID for "Backdraft" buff:
local BACKDRAFT_ID = 117828

-- Get the localized spell name and store it in a variable:
local BACKDRAFT = GetSpellInfo(BACKDRAFT_ID)

-- 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, BACKDRAFT_ID, "Textures\\SpellActivationOverlays\\Molten_Core", "LEFT", 1, 255, 255, 255, false, false)
    else
        -- No, they don't. Hide the overlay.
        SpellActivationOverlay_HideOverlays(SpellActivationOverlayFrame, BACKDRAFT_ID)
    end
end)
Only added a variable for the spellID, and escaped the "\" in the path, otherwise it's just how I'd write the code. :P
__________________
Profile: Curse | Wowhead
  Reply With Quote
01-07-13, 07:18 AM   #4
mchwxj
A Fallenroot Satyr
Join Date: Jan 2013
Posts: 20
Originally Posted by Phanx View Post
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.
Originally Posted by Vlad View Post
Here is your re-revised code:
Thank you guys~~ It's really a big help~~ And it also make me realize how little i know to express my gratitude in English~ haha~
  Reply With Quote

WoWInterface » AddOns, Compilations, Macros » AddOn Help/Support » Need help of LUA Code: Buff Monitor (Like Power Aura)


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