WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   AddOn Search/Requests (https://www.wowinterface.com/forums/forumdisplay.php?f=6)
-   -   Purge Addon Request (https://www.wowinterface.com/forums/showthread.php?t=53098)

Baggyman 01-27-16 12:46 PM

Purge Addon Request
 
Would it be possible to make an addon that only shows debuffs and purgeable buffs on the enemy unit and focus frames?

So essentially just get rid of all the buffs that I cannot purge.

Fizzlemizz 01-27-16 02:02 PM

Yes it's possible, check the documentation for UnitBuff and UnitDebuff and note the "dispelType" return of each.

Baggyman 01-27-16 04:55 PM

Can anyone help me out with the code on this.

I tried editing some other peoples existing code but it still isn't working. Are any of these 2 trys close:


UIParent:SetScript("OnUpdate", function()
if TargetFrame:IsShown() then
numBuffs = 0
for i=1, MAX_TARGET_BUFFS do
if (select(3,UnitBuff("target",i)) ~= 'Magic') then
numBuffs = numBuffs + 1
end
end
for i=1, numBuffs do
local frame = _G["TargetFrameBuff"..i]
frame:Hide()
end
end


OR


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

Baggyman 01-28-16 04:59 PM

Alright I figured it out! This is what I used if anyone else is interested:

hooksecurefunc("TargetFrame_UpdateAuras", function(s)
for i = 1, MAX_TARGET_BUFFS do
_, _, ic, _, dT = UnitBuff(s.unit, i)
if(ic and (not s.maxBuffs or i<=s.maxBuffs)) then
local frame = _G["TargetFrameBuff"..i]
if(dT~='Magic') then
frame:Hide()
end
end
end
end)


Also could someone explain to me what "not s.maxBuffs or i<=s.maxbuffs" is checking for? I got some of this code from around the web and am not quite sure what that part is for.

Clamsoda 01-28-16 05:29 PM

The logic you posted about is to prevent your loop from doing work on anything not visible. MAX_TARGET_BUFFS, which is the boundary for your loop, is a constant -- 32. self.maxBuffs is the current amount of buffs on the target, but understand that all 32 buff frames exist, and are used dynamically. So, that bit of logic prevents the loop from iterating past what buffs are currently displayed.

The code you posted leaks some very generic variables into the global name space, I posted a cleaned up version.

Lua Code:
  1. hooksecurefunc("TargetFrame_UpdateAuras", function(self)
  2.     for i = 1, MAX_TARGET_BUFFS do
  3.         local _, _, icon, _, dispelType = UnitBuff(self.unit, i)
  4.  
  5.         if (icon and (not self.maxBuffs or i <= self.maxBuffs) ) then
  6.             if (dispelType ~= "Magic") then
  7.                 _G["TargetFrameBuff"..i]:Hide()
  8.             end
  9.         end
  10.     end
  11. end)

Baggyman 01-28-16 05:53 PM

Thanks for the insight! But I'm not sure I quite fully understand what you are saying. What is the downside or implication if it can not iterate past what buffs are currently displayed?

Also I just tried out your revised logic, and it no longer seems to be hiding buffs.

Clamsoda 01-28-16 06:11 PM

I revised the code, typo =[.

Well, your intention is to manipulate the buffs that the target has, so there is no sense in iterating into the buff frames that are not currently being used.

Remember, frames for buff 1-32 exist, but only the buffs the target has are being used. So, if your target has 5 buffs, there is no point in iterating over the frames for buff 6-32 because they aren't being displayed to begin with.

Baggyman 01-28-16 06:15 PM

Ok that makes sense. But does your logic fix that? It seems you just changed out s with self, made line 3 local, and changed line 7.

Clamsoda 01-28-16 06:17 PM

Pardon me? The logic already existed in YOUR code, you asked what it does and I explained it. I kept the code, all I did was use naming conventions that make sense, got rid of the pointless assignment of the frame lookup to a variable, and made the variables local instead of spreading generic variable names into the global namespace.

My original code didn't work because I spelled "function" incorrectly.

Baggyman 01-28-16 06:22 PM

Oh I see, somehow I mixed up what you were trying to say. Thanks!

Also, if I could ask you 1 more thing. How could I apply this to the focus frame as well? Simply exchanging "target" with "focus" in every instance doesn't seem to be working for me.

Clamsoda 01-28-16 07:18 PM

This is a quick re-hash of the old code and seems to work for me.

The FocusFrame's buff handling piggybacks off of TargetFrame_UpdateAuras by being passed into the function as the self argument. My code identifies the name of the frame that self is referring to, and uses that to look up the appropriate icon frame to hide.

Simple enough, this has been happening in the background of this script the entire time, there has just been no work done to the FocusFrame's buff icons.

Lua Code:
  1. hooksecurefunc("TargetFrame_UpdateAuras", function(self)
  2.     for i = 1, MAX_TARGET_BUFFS do
  3.         local _, _, icon, _, dispelType = UnitBuff(self.unit, i)
  4.  
  5.         if (icon and (not self.maxBuffs or i <= self.maxBuffs) ) then
  6.             if (dispelType ~= "Magic") then
  7.                 _G[self:GetName().."Buff"..i]:Hide()
  8.             end
  9.         end
  10.     end
  11. end)

Baggyman 01-28-16 07:27 PM

Thanks so much man! You are awesome.


All times are GMT -6. The time now is 04:05 PM.

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