Thread Tools Display Modes
01-26-16, 02:47 AM   #1
Lesteryoung
A Black Drake
Join Date: Aug 2015
Posts: 81
Request for someone to turn two macro scripts into addons.

I know I could just throw these into a folder and they would probably work fine, but was just wondering if someone could clean them up.

Macro one puts the yellow border around dispellable buffs that is default for mages/shamans.. etc around all target/focus frame buffs for all classes and not just enemy target/focus.

Lua Code:
  1. hooksecurefunc("TargetFrame_UpdateAuras", function(s) for i=1,MAX_TARGET_BUFFS do if select(5,UnitAura(s.unit,i)) == 'Magic' then _G[s:GetName().."Buff"..(i).."Stealable"]:Show() end end end)

Macro two replaces the level text on the default nameplates to arenaID numbers when inside an arena. So arena target 123 instead of level 100.

Lua Code:
  1. C_Timer.NewTicker(.2,function()for A,P in pairs({WorldFrame:GetChildren()})do A=P.ArtContainer if A then for i=1,5 do if P.NameContainer.NameText:GetText()==GetUnitName("arena"..i)then A.LevelText:SetText(i)break end end end end end)
  Reply With Quote
01-31-16, 12:00 AM   #2
Lesteryoung
A Black Drake
Join Date: Aug 2015
Posts: 81
Bump

The first macro looks fine to me, but could someone show me how to indent it? I tried using an auto indentation program and it doesn't work on this code, it just keeps it at 1 line.

Not too concerned about the second macro, so unless someone is bored, don't worry about it.
  Reply With Quote
01-31-16, 04:23 PM   #3
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
You mean just this?
Lua Code:
  1. hooksecurefunc("TargetFrame_UpdateAuras", function(s)
  2.           for i=1,MAX_TARGET_BUFFS do
  3.                if select(5,UnitAura(s.unit,i)) == 'Magic' then
  4.                     _G[s:GetName().."Buff"..(i).."Stealable"]:Show()
  5.                end
  6.           end
  7.      end)
__________________
"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
01-31-16, 05:14 PM   #4
Lesteryoung
A Black Drake
Join Date: Aug 2015
Posts: 81
Yes, thank you.
  Reply With Quote
02-07-16, 10:34 AM   #5
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
While you're doing cleanup, you may as well go a little further and remove some inefficiencies that might make sense in the context of a space-limited macro, but don't make sense in an addon. The current code is doing two things that aren't so great:

1. It's looking up the name of the target frame over and over. The target frame shows up to 32 buffs at a time, so you're potentially calling the same function 32 times. You can easily call it just once, store the name in a variable, and refer to that inside your loop:

Code:
hooksecurefunc("TargetFrame_UpdateAuras", function(s)
          local name = s:GetName().."Buff"
          for i=1,MAX_TARGET_BUFFS do
               if select(5,UnitAura(s.unit,i)) == 'Magic' then
                    _G[name..i.."Stealable"]:Show()
               end
          end
     end)
2. It's using the select function. Unless you're selecting value 940382423 out of a list, or are in some weird context where variables aren't an option, it's just a waste of CPU cycles. Just assign the return values and ignore the ones you don't need:

Code:
hooksecurefunc("TargetFrame_UpdateAuras", function(s)
          local name = s:GetName().."Buff"
          for i=1,MAX_TARGET_BUFFS do
               local _,_,_,_,buffType=UnitAura(s.unit,i)
               if buffType == 'Magic' then
                    _G[name..i.."Stealable"]:Show()
               end
          end
     end)
Calling functions is the slowest thing you can do in an addon, so it's always good to avoid doing it more than you need to, especially in a situation like this one where your code is going to run very frequently.

Finally (not related to performance) you can add more whitespace to improve readability:

Code:
hooksecurefunc("TargetFrame_UpdateAuras", function(s)
          local name = s:GetName() .. "Buff"
          for i = 1 ,MAX_TARGET_BUFFS do
               local _, _, _, _, buffType = UnitAura(s.unit, i)
               if buffType == 'Magic' then
                    _G[name .. i .. "Stealable"]:Show()
               end
          end
     end)
__________________
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

WoWInterface » AddOns, Compilations, Macros » AddOn Search/Requests » Request for someone to turn two macro scripts into addons.

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