Thread Tools Display Modes
04-21-16, 07:43 AM   #1
kruma
A Deviate Faerie Dragon
Join Date: Jun 2012
Posts: 15
Reverse code

Hi!
Help me someone with code. Need reverse when missing buff indicator=show, when have buffs indicator hide

Code:
local indicators = {}
local buffs = {}
local_, class = UnitClass("player");
 
if ( class == "DRUID" ) then
buffs = {["Mark of the Wild"] = true}
end
if (class == "PRIEST" ) then
buffs = {["Power Word: Fortitude"] = true}
end
if (class == "MAGE" ) then
buffs = {["Arcane Brilliance"] = true}
end
if (class == "MONK" ) then
buffs = {
["Legacy of the White Tiger"] = true,
["Legacy of the Emperor"] = true
}
end
if (class == "DEATHKNIGHT" ) then
buffs = {["Horn of Winter"] = true}
end
if (class == "PALADIN" ) then
buffs = {
["Blessing of Kings"] = true,
["Blessing of Might"] = true
}
end
if (class == "WARLOCK" ) then
buffs = {["Dark Intent"] = true}
end
if (class == "WARRIOR" ) then
buffs = {
["Battle Shout"] = true,
["Commanding Shout"] = true
}
end
 
 
 
local function getIndicator(frame)
local indicator = indicators[frame:GetName()]
if not indicator then
indicator = CreateFrame("Button", nil, frame, "CompactAuraTemplate")
indicator:ClearAllPoints()
indicator:SetPoint("TOPRIGHT", frame, "TOPRIGHT", -3, -2)
indicator:SetSize(22, 22)
indicator:SetAlpha(0.6)
indicators[frame:GetName()] = indicator
end
return indicator
end
 
local function updateBuffs(frame)
if not frame:IsVisible() then return end
 
local indicator = getIndicator(frame)
local buffName = nil
for i = 1, 40 do
local _, _, _, _, _, d, _, ut, _, sc, s, c = UnitBuff(frame.displayedUnit, i);
buffName = UnitBuff(frame.displayedUnit, i);
if not buffName then break end
if buffs[buffName] and ( ut == "player" or ut == "pet" ) then
indicator:SetSize(frame.buffFrames[1]:GetSize()) -- scale
CompactUnitFrame_UtilSetBuff(indicator, frame.displayedUnit, i, nil);
return
end
end
indicator:Hide()
end
hooksecurefunc("CompactUnitFrame_UpdateBuffs", updateBuffs)
  Reply With Quote
04-21-16, 02:23 PM   #2
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,326
There's a lot of places in this code that needs improvement. First of all, you shouldn't be looking for buffs by name. This will only work on one locale (client language) and not others. You should use SpellIDs instead.

Also, storing pointers by frame name will oftentimes get you into trouble as not all frames are named. This will make you run into "index by nil" errors when this happens. You should reference by the frame pointer itself. This is completely unique and is never nil.



Overall, the problem with an addon like this is the fact that buffs that modify the same stat type override each other. This may lead to two or more players fighting over whether or not their buff is up because they keep overriding each other. This is where having consolidated buffs on is helpful so you can tell what stat types are being buffed and remember what your buff does as part of knowing your class.

Anyway, here's a much better implementation of your code. Doing what you're describing, performing the inverse of showing/hiding the frame, is practically impossible in design. This is because a few of the classes have to choose which buff they activate which are mutually exclusive.

Lua Code:
  1. local IndicatorLookup={};
  2. local BuffList={
  3. --  Death Knight
  4.     [57330]=true;--     Horn of Winter
  5.  
  6. --  Druid
  7.     [1126]=true;--      Mark of the Wild
  8.  
  9. --  Mage
  10.     [1459]=true;--      Arcane Brilliance
  11.     [61316]=true;--     Dalaran Brilliance
  12.  
  13. --  Monk
  14.     [115921]=true;--    Legacy of the Emperor
  15.     [116781]=true;--    Legacy of the White Tiger
  16.  
  17. --  Paladin
  18.     [19740]=true;--     Blessing of Might
  19.     [20217]=true;--     Blessing of Kings
  20.  
  21. --  Priest
  22.     [21562]=true;--     Power Word: Fortitude
  23.  
  24. --  Warlock
  25.     [109773]=true;--    Dark Intent
  26.  
  27. --  Warrior
  28.     [6673]=true;--      Battle Shout
  29.     [469]=true;--       Commanding Shout
  30. };
  31.  
  32. hooksecurefunc("CompactUnitFrame_UpdateBuffs",function(self)
  33.     if not self:IsVisible() then return; end
  34.  
  35.     local unit,index=self.displayedUnit,1;--    Prepare variables for loop
  36.     repeat
  37.         local _,_,_,_,_,_,_,caster,_,_,spellid=UnitBuff(unit,index);--  Grab buffs cast by us
  38.         if spellid then--   Buff exists?
  39.             if (caster=="player" or caster=="pet" or caster=="vehicle") and BuffList[spellid] then break; end-- If we found our buff, break out of loop
  40.             index=index+1;--    Increment index
  41.         else
  42.             index=nil;--    Else clear index
  43.         end
  44.     until not spellid-- Stop if no more buffs
  45.  
  46. --  At this point, Index will hold our found buff,
  47.     local frame=IndicatorLookup[self];
  48.     if not frame then
  49. --      If we didn't find our buff, then don't bother creating a frame
  50.         if not index then return; end
  51.  
  52.         frame=CreateFrame("Button",nil,self,"CompactAuraTemplate");
  53.         frame:ClearAllPoints();
  54.         frame:SetPoint("TOPRIGHT",-3,-2);
  55.         frame:SetSize(self.buffFrames[1]:GetSize());
  56.         frame:SetAlpha(0.6);
  57.         IndicatorLookup[self]=frame;
  58.     end
  59.  
  60.     if index then CompactUnitFrame_UtilSetBuff(frame,unit,index,"PLAYER"); end--    Apply buff found to template
  61.     frame:SetShown(index and true or false);--  Typecast to boolean
  62. end);
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)

Last edited by SDPhantom : 04-22-16 at 06:59 PM.
  Reply With Quote
04-22-16, 06:19 PM   #3
kruma
A Deviate Faerie Dragon
Join Date: Jun 2012
Posts: 15
Doing what you're describing, performing the inverse of showing/hiding the frame, is practically impossible in design
Is it possible to show/hide buffs only casted by me? Executed code show all bufflist http://imgur.com/QVUJ4Sq
maybe if the point buffs casted by me(player) can be inverted(if miss then show else hide)?

Last edited by kruma : 04-22-16 at 06:39 PM.
  Reply With Quote
04-22-16, 06:59 PM   #4
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,326
Updated lines 37 and 39. The "PLAYER" filter wasn't doing what I thought it would. It was filtering buffs they cast and not ours.

Anyway, as I explained before, it's easy to show which buff we cast on a player. Design-wise, how do you want to implement multiple buff options in a "buff missing" indicator? Do you want to show all buff options, taking up more room on the UnitFrame?

For example, a Warrior can use either Battle Shout or Commanding Shout to buff the raid. Which of these do you want to show if neither of them have been applied? Do you want both of them to show up at the same time? Wouldn't it be much easier if we have the indicator show if they have our buff instead?
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)

Last edited by SDPhantom : 04-22-16 at 07:07 PM.
  Reply With Quote
04-23-16, 05:55 AM   #5
kruma
A Deviate Faerie Dragon
Join Date: Jun 2012
Posts: 15
Originally Posted by SDPhantom View Post
Updated lines 37 and 39. The "PLAYER" filter wasn't doing what I thought it would. It was filtering buffs they cast and not ours.

Anyway, as I explained before, it's easy to show which buff we cast on a player. Design-wise, how do you want to implement multiple buff options in a "buff missing" indicator? Do you want to show all buff options, taking up more room on the UnitFrame?

For example, a Warrior can use either Battle Shout or Commanding Shout to buff the raid. Which of these do you want to show if neither of them have been applied? Do you want both of them to show up at the same time? Wouldn't it be much easier if we have the indicator show if they have our buff instead?
i have icon created by addon tellmewhen settings - http://imgur.com/td423TD
can you help me rewrite code what need to show
if missing (buff=idspell and buff(casted by me)) then show indicator attached to raid frames
  Reply With Quote
04-23-16, 12:26 PM   #6
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,326
So you just want a static icon shown regardless of what buff spell(s) are missing? If that's the case, then here's a modified version that does just that. Though I don't find the idea of disassociation to make much sense.

Lua Code:
  1. local IndicatorLookup={};
  2. local BuffList={
  3. --  Death Knight
  4.     [57330]=true;--     Horn of Winter
  5.  
  6. --  Druid
  7.     [1126]=true;--      Mark of the Wild
  8.  
  9. --  Mage
  10.     [1459]=true;--      Arcane Brilliance
  11.     [61316]=true;--     Dalaran Brilliance
  12.  
  13. --  Monk
  14.     [115921]=true;--    Legacy of the Emperor
  15.     [116781]=true;--    Legacy of the White Tiger
  16.  
  17. --  Paladin
  18.     [19740]=true;--     Blessing of Might
  19.     [20217]=true;--     Blessing of Kings
  20.  
  21. --  Priest
  22.     [21562]=true;--     Power Word: Fortitude
  23.  
  24. --  Warlock
  25.     [109773]=true;--    Dark Intent
  26.  
  27. --  Warrior
  28.     [6673]=true;--      Battle Shout
  29.     [469]=true;--       Commanding Shout
  30. };
  31.  
  32. local Icon; do
  33.     local ClassIcons={
  34.         DEATHKNIGHT =57330;--   Horn of Winter
  35.         DRUID       =1126;--    Mark of the Wild
  36.         MAGE        =1459;--    Arcane Brilliance
  37.         MONK        =115921;--  Legacy of the Emperor
  38.         PALADIN     =19740;--   Blessing of Might
  39.         PRIEST      =21562;--   Power Word: Fortitude
  40.         WARLOCK     =109773;--  Dark Intent
  41.         WARRIOR     =6673;--    Battle Shout
  42.     };
  43.  
  44. --  Set class-based icon
  45.     local Buff=ClassIcons[select(2,UnitClass("player"))];
  46.     Icon=Buff and GetSpellTexture(Buff);
  47. end
  48.  
  49. hooksecurefunc("CompactUnitFrame_UpdateBuffs",function(self)
  50.     if not self:IsVisible() then return; end
  51.  
  52.     local unit,index=self.displayedUnit,1;--    Prepare variables for loop
  53.     repeat
  54.         local _,_,_,_,_,_,_,caster,_,_,spellid=UnitBuff(unit,index);--  Grab buffs cast by us
  55.         if spellid then--   Buff exists?
  56.             if (caster=="player" or caster=="pet" or caster=="vehicle") and BuffList[spellid] then break; end-- If we found our buff, break out of loop
  57.             index=index+1;--    Increment index
  58.         else
  59.             index=nil;--    Else clear index
  60.         end
  61.     until not spellid-- Stop if no more buffs
  62.  
  63. --  At this point, Index will hold our found buff,
  64.     local tex=IndicatorLookup[self];
  65.     if not tex then
  66. --      If we found a buff, then don't bother creating a frame
  67.         if not index then return; end
  68.  
  69.         tex=self:CreateTexture(nil,"OVERLAY");
  70.         tex:SetPoint("TOPRIGHT",-3,-2);
  71.         tex:SetSize(self.buffFrames[1]:GetSize());
  72.         tex:SetTexture(Icon);
  73.         tex:SetAlpha(0.6);
  74.         IndicatorLookup[self]=tex;
  75.     end
  76.  
  77.     tex:SetShown(not index);
  78. end);

Note: all the spells in Legion have been switched around, so the spell IDs will need to be updated when it goes live.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)

Last edited by SDPhantom : 04-24-16 at 12:44 PM.
  Reply With Quote
04-24-16, 05:06 AM   #7
kruma
A Deviate Faerie Dragon
Join Date: Jun 2012
Posts: 15
Thanks great work, it`s working properly. One moment only, is it possible attach
Code:
    local Icon="Interface\\Icons\\Ability_monk_legacyoftheemperor";-- GetSpellTexture(19740)
to player class
for example if (player_class=monk) then Icon="Interface\\Icons\\Ability_monk_legacyoftheemperor"
all icons

Code:
monk - Ability_monk_legacyoftheemperor
druid - Spell_nature_regeneration
mage - spell_holy_magicalsentry
paladin - Spell_holy_greaterblessingofkings
priest - spell_holy_wordfortitude
warlock - spell_warlock_focusshadow
the reason why i need show indicator when buff missing to keep track when my big buffs was purged. It helping me rebuff my arena mates
  Reply With Quote
04-24-16, 12:45 PM   #8
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,326
Updated the previous post to select a buff icon based on class.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)
  Reply With Quote
04-24-16, 07:53 PM   #9
kruma
A Deviate Faerie Dragon
Join Date: Jun 2012
Posts: 15
biggest thanks SDPhantom for help
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Reverse code


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