WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   AddOn Search/Requests (https://www.wowinterface.com/forums/forumdisplay.php?f=6)
-   -   Request for someone to turn two macro scripts into addons. (https://www.wowinterface.com/forums/showthread.php?t=53091)

Lesteryoung 01-26-16 02:47 AM

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)

Lesteryoung 01-31-16 12:00 AM

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.

Seerah 01-31-16 04:23 PM

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)

Lesteryoung 01-31-16 05:14 PM

Yes, thank you.

Phanx 02-07-16 10:34 AM

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)



All times are GMT -6. The time now is 01:49 PM.

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