Thread Tools Display Modes
11-14-22, 07:31 AM   #1
Nieub Barmy
A Murloc Raider
 
Nieub Barmy's Avatar
Join Date: Nov 2022
Posts: 4
Activate/Deactivate addon function in game

Hi

I have put together a simple addon to remove the buffs from my target frame and it works fine. I now wish to create an option in game to toggle the buffs on and off and would love some advice on the simplest way to do this.

LUA File attached


Thanks all in advance.
Attached Files
File Type: lua BuffOff.lua (600 Bytes, 31 views)

Last edited by Nieub Barmy : 07-05-23 at 03:27 AM. Reason: To add LUA Attachment
  Reply With Quote
11-14-22, 01:18 PM   #2
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,323
This creates a SavedVariable and a simple options panel.

Be sure to add this to your ToC to flag your SavedVariable for saving.
Code:
## SavedVariables: BuffOff_Options
Lua Code:
  1. local AddOn_Name=...;-- Grab our AddOn's name passed in from the loading process (This is basically our folder's name)
  2. local AddOn_Title=select(2,GetAddOnInfo(AddOn_Name)) or AddOn_Name;-- Attempt to retrieve our "Title" tag from our ToC if it's set
  3.  
  4. BuffOff_Options={-- Declare our SavedVariable
  5.     TargetFrameBuffs=false;
  6.     FocusFrameBuffs=false;
  7. };
  8.  
  9. --  Options Panel Layout
  10. local OptionsPanel=CreateFrame("Frame");
  11.  
  12. local TitleText=OptionsPanel:CreateFontString(nil,"OVERLAY","GameFontNormal");
  13. TitleText:SetPoint("TOP",0,-32);
  14. TitleText:SetText(AddOn_Title);
  15.  
  16. local TargetFrame_HideBuffs=CreateFrame("CheckButton",nil,OptionsPanel,"UICheckButtonTemplate");
  17. TargetFrame_HideBuffs:SetPoint("TOPLEFT",24,-48);
  18. TargetFrame_HideBuffs.text:SetText("Hide TargetFrame Buffs");
  19. TargetFrame_HideBuffs:SetScript("OnClick",function(self)--  Fire on user click (Toggles check status)
  20.     BuffOff_Options.TargetFrameBuffs=self:GetChecked();--   Update SavedVariable
  21.     TargetFrame_UpdateAuras(TargetFrame);-- Trigger aura update
  22. end);
  23.  
  24. local FocusFrame_HideBuffs=CreateFrame("CheckButton",nil,OptionsPanel,"UICheckButtonTemplate");
  25. FocusFrame_HideBuffs:SetPoint("TOPLEFT",24,-72);
  26. FocusFrame_HideBuffs.text:SetText("Hide FocusFrame Buffs");
  27. FocusFrame_HideBuffs:SetScript("OnClick",function(self)--   Fire on user click (Toggles check status)
  28.     BuffOff_Options.FocusFrameBuffs=self:GetChecked();--    Update SavedVariable
  29.     TargetFrame_UpdateAuras(FocusFrame);--  Trigger aura update
  30. end);
  31.  
  32. --  Options Panel Registration & Callbacks
  33. OptionsPanel.name=AddOn_Title;--    Category name
  34. OptionsPanel.refresh=function()--   Runs when our Options Panel is shown
  35.     TargetFrame_HideBuffs:SetChecked(BuffOff_Options.TargetFrameBuffs or false);
  36.     FocusFrame_HideBuffs:SetChecked(BuffOff_Options.FocusFrameBuffs or false);
  37. end;
  38.  
  39. InterfaceOptions_AddCategory(OptionsPanel);--   Register our Options Panel
  40.  
  41. --  Hook
  42. hooksecurefunc("TargetFrame_UpdateAuras",function(self)
  43.     if self~=TargetFrame and self~=FocusFrame then return; end--    Filter for these two frames
  44.  
  45.     local framename=self:GetName();
  46.     if not BuffOff_Options[framename.."Buffs"] then return; end--   Read from our SavedVariable
  47.  
  48.     for index=1,MAX_TARGET_BUFFS do
  49.         local buff=_G[framename.."Buff"..index];
  50.         if buff then
  51.             buff:Hide();
  52.         else break; end
  53.     end
  54.  
  55.     for index=1,MAX_TARGET_DEBUFFS do
  56.         local debuff=_G[framename.."Debuff"..index];
  57.         if debuff then
  58.             debuff:Hide();
  59.         else break; end
  60.     end
  61. 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 : 11-16-22 at 02:24 PM.
  Reply With Quote
11-15-22, 06:49 AM   #3
Nieub Barmy
A Murloc Raider
 
Nieub Barmy's Avatar
Join Date: Nov 2022
Posts: 4
Thank you for your help its really appreciated. FYI, I am currently attempting to learn LUA as a hobby and kind of reverse engineering the code to figure out how it works. To complete this addon and understand how it works will be a wonderful milestone for me.

That being said I have pasted the LUA you gave me and it doesnt work completely. I have an options menu called BuffsOff and 2 checkboxes within however there is no text with the checkboxes (Hide TargetFrame Buffs & Hide FocusFrame Buffs) and whether checked or not party frame buffs are still visible.
Attached Thumbnails
Click image for larger version

Name:	WoWScrnShot_111522_135027.jpg
Views:	51
Size:	378.9 KB
ID:	9764  

Last edited by Nieub Barmy : 11-15-22 at 06:52 AM. Reason: changed attachment
  Reply With Quote
11-15-22, 03:19 PM   #4
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,323
Apparently, the template used doesn't register its FontString with the button, so button:SetText() isn't referencing it. I fixed this in the original post changing the relevant calls to button.text:SetText().
__________________
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
11-16-22, 01:54 AM   #5
Nieub Barmy
A Murloc Raider
 
Nieub Barmy's Avatar
Join Date: Nov 2022
Posts: 4
Whoop, its working great now, I just had to change the hook from:

hooksecurefunc("TargetFrame_UpdateAuras", function(self)
if self ~= TargetFrame and self ~= FocusFrame then return end

to:

hooksecurefunc("TargetFrame_UpdateAuras", function(frame)
if frame ~= TargetFrame and frame ~= FocusFrame then return end

Thank you again for your help

xx
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Activate/Deactivate addon function in game


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