Thread Tools Display Modes
11-28-22, 12:52 AM   #1
MadhatterMB
A Kobold Labourer
Join Date: Nov 2022
Posts: 1
Can someone code review me?

So I'm brand new to LUA and this is an attempt at putting together an addon to toggle on and off frames. So far in testing(about 3 days worth) everything was working great up until a couple hours ago(of course right before df drops). I believe I was encountering tainting issues when entering dungeon instances. The raid manager as well as random other parts of the UI would toggle themselves on and I would get random LUA errors for addons that weren't even operational. When I traced the taint log I believe my own addon was causing the issue. Can anyone give me pointers to prevent tainting or maybe let me know if it all looks OK. (there is a slight possibility it wasn't my addon, but instead a weak aura that I was playing with). TIA!
Lua Code:
  1. -- variables
  2.  
  3. local defaults = {
  4.     togglecastbar = false,
  5.     togglebuffframe = false,
  6.     toggledebuffframe = false,
  7.     toggleplayerframe = false,
  8.     togglefocusframe = false,
  9.     toggletargetframe = false,
  10.     togglepetframe = false,
  11.     toggleraidframe = false,
  12.     toggleraidframemanager = false,
  13.     togglepartyframe = false,
  14.     togglebossframe = false
  15. }
  16.  
  17. --initial load and set state
  18.  
  19. local function OnEvent(self, event, addOnName)
  20.     if addOnName == "HideEverything" then
  21.         if not State then
  22.             initMessage = WrapTextInColorCode("\nHideEverything loaded for the first time!\nEverything is hidden by default.\nUse /HE for instructions", "FF8C6FFF")
  23.             print(initMessage)
  24.         end
  25.         State = State or {}
  26.         self.state = State
  27.         for k, v in pairs(defaults) do
  28.             if self.state[k] == nil then
  29.                 self.state[k] = v
  30.             end
  31.         end
  32.         if not self.state.togglecastbar then
  33.             PlayerCastingBarFrame:UnregisterAllEvents()
  34.         end
  35.         if not self.state.togglebuffframe then
  36.             BuffFrame:Hide()
  37.         end
  38.         if not self.state.toggledebuffframe then
  39.             DebuffFrame:Hide()
  40.         end
  41.         if not self.state.toggleplayerframe then
  42.             PlayerFrame:UnregisterAllEvents()
  43.             PlayerFrame:Hide()
  44.         end
  45.         if not self.state.togglefocusframe then
  46.             FocusFrame:UnregisterAllEvents()
  47.             FocusFrame:Hide()
  48.         end
  49.         if not self.state.toggletargetframe then
  50.             TargetFrame:UnregisterAllEvents()
  51.             TargetFrame:Hide()
  52.         end
  53.         if not self.state.togglepetframe then
  54.             PetFrame:UnregisterAllEvents()
  55.             PetFrame:Hide()
  56.         end
  57.         if not self.state.toggleraidframe then
  58.             CompactRaidFrameContainer:UnregisterAllEvents()
  59.             CompactRaidFrameContainer:Hide()
  60.         end
  61.         if not self.state.toggleraidframemanager then
  62.             CompactRaidFrameContainer:UnregisterAllEvents()
  63.             CompactRaidFrameContainer:Hide()
  64.             CompactRaidFrameManager:UnregisterAllEvents()
  65.             CompactRaidFrameManager:Hide()
  66.         end
  67.         if not self.state.togglepartyframe then
  68.             PartyFrame:UnregisterAllEvents()
  69.             PartyFrame:Hide()
  70.         end
  71.         if not self.state.togglebossframe then
  72.             BossTargetFrameContainer:UnregisterAllEvents()
  73.             BossTargetFrameContainer:Hide()
  74.         end
  75.         local version, build, _, tocversion = GetBuildInfo()
  76.     end
  77. end
  78.  
  79. local f = CreateFrame("Frame")
  80. f:RegisterEvent("ADDON_LOADED")
  81. f:SetScript("OnEvent", OnEvent)
  82.  
  83. --toggle the castbar
  84.  
  85. SLASH_CASTBAR1 = "/castbarframe"
  86.  
  87. SlashCmdList.CASTBAR = function(msg, editBox)
  88.     ToggleCastBarFrameFunc()
  89. end
  90.  
  91.     function ToggleCastBarFrameFunc()
  92.     if not InCombatLockdown() then
  93.         if f.state.togglecastbar then
  94.         PlayerCastingBarFrame:UnregisterAllEvents()
  95.         elseif not f.state.togglecastbar then
  96.         PlayerCastingBarFrame:RegisterAllEvents()
  97.         end
  98.         f.state.togglecastbar = not f.state.togglecastbar
  99.         print(WrapTextInColorCode("Cast Bar is ", "FF8C6FFF") .. (f.state.togglecastbar and WrapTextInColorCode("Showing", "FF00FF00") or WrapTextInColorCode("Hidden", "FFFF0000")))
  100.     else
  101.         print(WrapTextInColorCode("Please wait until you are out of Combat to toggle frames", "FFFF0000"))
  102.     end
  103. end
  104.  
  105.  
  106. --toggle the buff frame
  107.  
  108. SLASH_BUFFFRAME1 = "/buffsframe"
  109.  
  110. SlashCmdList.BUFFFRAME = function(msg, editBox)
  111.     ToggleBuffFrameFunc()
  112. end
  113.  
  114.     function ToggleBuffFrameFunc()
  115.     if not InCombatLockdown() then
  116.         if f.state.togglebuffframe then
  117.         BuffFrame:Hide()
  118.         elseif not f.state.togglebuffframe then
  119.         BuffFrame:Show()
  120.         end
  121.         f.state.togglebuffframe = not f.state.togglebuffframe
  122.         print(WrapTextInColorCode("Buff Frame is ", "FF8C6FFF") .. (f.state.togglebuffframe and WrapTextInColorCode("Showing", "FF00FF00") or WrapTextInColorCode("Hidden", "FFFF0000")))
  123.     else
  124.         print(WrapTextInColorCode("Please wait until you are out of Combat to toggle frames", "FFFF0000"))
  125.     end
  126. end
  127.  
  128. --toggle the debuff frame
  129.  
  130. SLASH_DEBUFFFRAME1 = "/debuffsframe"
  131.  
  132. SlashCmdList.DEBUFFFRAME = function(msg, editBox)
  133.     ToggleDebuffFrameFunc()
  134. end
  135.  
  136.     function ToggleDebuffFrameFunc()
  137.     if not InCombatLockdown() then
  138.         if f.state.toggledebuffframe then
  139.         DebuffFrame:Hide()
  140.         elseif not f.state.toggledebuffframe then
  141.         DebuffFrame:Show()
  142.         end
  143.         f.state.toggledebuffframe = not f.state.toggledebuffframe
  144.         print(WrapTextInColorCode("Debuff Frame is ", "FF8C6FFF") .. (f.state.toggledebuffframe and WrapTextInColorCode("Showing", "FF00FF00") or WrapTextInColorCode("Hidden", "FFFF0000")))
  145.     else
  146.         print(WrapTextInColorCode("Please wait until you are out of Combat to toggle frames", "FFFF0000"))
  147.     end
  148. end
  149.  
  150. --toggle the player frame
  151.  
  152. SLASH_PLAYERFRAME1 = "/playerframe"
  153.  
  154. SlashCmdList.PLAYERFRAME = function(msg, editBox)
  155.     TogglePlayerFrameFunc()
  156. end
  157.  
  158. function TogglePlayerFrameFunc()
  159.     if not InCombatLockdown() then
  160.         if f.state.toggleplayerframe then
  161.         PlayerFrame:UnregisterAllEvents()
  162.         PlayerFrame:Hide()
  163.         elseif not f.state.toggleplayerframe then
  164.         PlayerFrame:RegisterAllEvents()
  165.         PlayerFrame:Show()
  166.         end
  167.         f.state.toggleplayerframe = not f.state.toggleplayerframe
  168.         print(WrapTextInColorCode("Player Frame is ", "FF8C6FFF") .. (f.state.toggleplayerframe and WrapTextInColorCode("Showing", "FF00FF00") or WrapTextInColorCode("Hidden", "FFFF0000")))
  169.     else
  170.         print(WrapTextInColorCode("Please wait until you are out of Combat to toggle frames", "FFFF0000"))
  171.     end
  172. end
  173.  
  174. --toggle the focus frame
  175.  
  176. SLASH_FOCUSFRAME1 = "/focusframe"
  177.  
  178. SlashCmdList.FOCUSFRAME = function(msg, editBox)
  179.     ToggleFocusFrameFunc()
  180. end
  181.  
  182.     function ToggleFocusFrameFunc()
  183.     if not InCombatLockdown() then
  184.         if f.state.togglefocusframe then
  185.         FocusFrame:UnregisterAllEvents()
  186.         FocusFrame:Hide()
  187.         elseif not f.state.togglefocusframe then
  188.         FocusFrame:RegisterAllEvents()
  189.         FocusFrame:Show()
  190.         end
  191.         f.state.togglefocusframe = not f.state.togglefocusframe
  192.         print(WrapTextInColorCode("Focus Frame is ", "FF8C6FFF") .. (f.state.togglefocusframe and WrapTextInColorCode("Showing", "FF00FF00") or WrapTextInColorCode("Hidden", "FFFF0000")))
  193.     else
  194.         print(WrapTextInColorCode("Please wait until you are out of Combat to toggle frames", "FFFF0000"))
  195.     end
  196. end
  197.  
  198. --toggle the target frame
  199.  
  200. SLASH_TARGETFRAME1 = "/targetframe"
  201.  
  202. SlashCmdList.TARGETFRAME = function(msg, editBox)
  203.     ToggleTargetFrameFunc()
  204. end
  205.  
  206.     function ToggleTargetFrameFunc()
  207.     if not InCombatLockdown() then
  208.         if f.state.toggletargetframe then
  209.         TargetFrame:UnregisterAllEvents()
  210.         TargetFrame:Hide()
  211.         elseif not f.state.toggletargetframe then
  212.         TargetFrame:RegisterAllEvents()
  213.         TargetFrame:Show()
  214.         end
  215.         f.state.toggletargetframe = not f.state.toggletargetframe
  216.         print(WrapTextInColorCode("Target Frame is ", "FF8C6FFF") .. (f.state.toggletargetframe and WrapTextInColorCode("Showing", "FF00FF00") or WrapTextInColorCode("Hidden", "FFFF0000")))
  217.     else
  218.         print(WrapTextInColorCode("Please wait until you are out of Combat to toggle frames", "FFFF0000"))
  219.     end
  220. end
  221.  
  222. --toggle the pet frame
  223.  
  224. SLASH_PETFRAME1 = "/petframe"
  225.  
  226. SlashCmdList.PETFRAME = function(msg, editBox)
  227.     TogglePetFrameFunc()
  228. end
  229.  
  230.     function TogglePetFrameFunc()
  231.     if not InCombatLockdown() then
  232.         if f.state.togglepetframe then
  233.         PetFrame:UnregisterAllEvents()
  234.         PetFrame:Hide()
  235.         elseif not f.state.togglepetframe then
  236.         PetFrame:RegisterAllEvents()
  237.         PetFrame:Show()
  238.         end
  239.         f.state.togglepetframe = not f.state.togglepetframe
  240.         print(WrapTextInColorCode("Pet Frame is ", "FF8C6FFF") .. (f.state.togglepetframe and WrapTextInColorCode("Showing", "FF00FF00") or WrapTextInColorCode("Hidden", "FFFF0000")))
  241.     else
  242.         print(WrapTextInColorCode("Please wait until you are out of Combat to toggle frames", "FFFF0000"))
  243.     end
  244. end
  245.  
  246.  
  247. --toggle the raid frame
  248.  
  249. SLASH_RAIDFRAME1 = "/raidframe"
  250.  
  251. SlashCmdList.RAIDFRAME = function(msg, editBox)
  252.     ToggleRaidFrameFunc()
  253. end
  254.  
  255.     function ToggleRaidFrameFunc()
  256.     if not InCombatLockdown() then
  257.         if f.state.toggleraidframe then
  258.         CompactRaidFrameContainer:UnregisterAllEvents()
  259.         CompactRaidFrameContainer:Hide()
  260.         elseif not f.state.toggleraidframe then
  261.         CompactRaidFrameContainer:RegisterAllEvents()
  262.         CompactRaidFrameContainer:Show()
  263.         end
  264.         f.state.toggleraidframe = not f.state.toggleraidframe
  265.         print(WrapTextInColorCode("Raid Frame is ", "FF8C6FFF") .. (f.state.toggleraidframe and WrapTextInColorCode("Showing", "FF00FF00") or WrapTextInColorCode("Hidden", "FFFF0000")))
  266.     else
  267.         print(WrapTextInColorCode("Please wait until you are out of Combat to toggle frames", "FFFF0000"))
  268.     end
  269. end
  270.  
  271. --toggle the raid frame manager
  272.  
  273. SLASH_RAIDFRAMEMANAGER1 = "/raidmanagerframe"
  274.  
  275. SlashCmdList.RAIDFRAMEMANAGER = function(msg, editBox)
  276.     ToggleRaidManagerFrameFunc()
  277. end
  278.  
  279.     function ToggleRaidManagerFrameFunc()
  280.     if not InCombatLockdown() then
  281.         if f.state.toggleraidframemanager then
  282.         CompactRaidFrameContainer:UnregisterAllEvents()
  283.         CompactRaidFrameContainer:Hide()
  284.         CompactRaidFrameManager:UnregisterAllEvents()
  285.         CompactRaidFrameManager:Hide()
  286.         elseif not f.state.toggleraidframemanager then
  287.         CompactRaidFrameManager:RegisterAllEvents()
  288.         CompactRaidFrameManager:Show()
  289.         end
  290.         f.state.toggleraidframemanager = not f.state.toggleraidframemanager
  291.         print(WrapTextInColorCode("Raid Frame Manager is ", "FF8C6FFF") .. (f.state.toggleraidframemanager and WrapTextInColorCode("Showing", "FF00FF00") or WrapTextInColorCode("Hidden", "FFFF0000")))
  292.     else
  293.         print(WrapTextInColorCode("Please wait until you are out of Combat to toggle frames", "FFFF0000"))
  294.     end
  295. end
  296.  
  297. --toggle the party frame
  298.  
  299. SLASH_PARTYFRAME1 = "/partyframe"
  300.  
  301. SlashCmdList.PARTYFRAME = function(msg, editBox)
  302.     TogglePartyFrameFunc()
  303. end
  304.  
  305.     function TogglePartyFrameFunc()
  306.     if not InCombatLockdown() then
  307.         if f.state.togglepartyframe then
  308.         PartyFrame:UnregisterAllEvents()
  309.         PartyFrame:Hide()
  310.         elseif not f.state.togglepartyframe then
  311.         PartyFrame:RegisterAllEvents()
  312.         PartyFrame:Show()
  313.         end
  314.         f.state.togglepartyframe = not f.state.togglepartyframe
  315.         print(WrapTextInColorCode("Party Frame is ", "FF8C6FFF") .. (f.state.togglepartyframe and WrapTextInColorCode("Showing", "FF00FF00") or WrapTextInColorCode("Hidden", "FFFF0000")))
  316.     else
  317.         print(WrapTextInColorCode("Please wait until you are out of Combat to toggle frames", "FFFF0000"))
  318.     end
  319. end
  320.  
  321. --toggle the boss frame
  322.  
  323. SLASH_BOSSFRAME1 = "/bossframe"
  324.  
  325. SlashCmdList.BOSSFRAME = function(msg, editBox)
  326.     ToggleBossFrameFunc()
  327. end
  328.  
  329.     function ToggleBossFrameFunc()
  330.     if not InCombatLockdown() then
  331.         if f.state.togglebossframe then
  332.             BossTargetFrameContainer:UnregisterAllEvents()
  333.             BossTargetFrameContainer:Hide()
  334.         elseif not f.state.togglebossframe then
  335.             BossTargetFrameContainer:RegisterAllEvents()
  336.             BossTargetFrameContainer:Show()
  337.         end
  338.         f.state.togglebossframe = not f.state.togglebossframe
  339.         print(WrapTextInColorCode("Boss Frame is ", "FF8C6FFF") .. (f.state.togglebossframe and WrapTextInColorCode("Showing", "FF00FF00") or WrapTextInColorCode("Hidden", "FFFF0000")))
  340.     else
  341.         print(WrapTextInColorCode("Please wait until you are out of Combat to toggle frames", "FFFF0000"))
  342.     end
  343. end
  344.  
  345. --toggle instructions
  346.  
  347. SLASH_TOGGLE1 = "/HE"
  348. SLASH_TOGGLE2 = "/HideEverything"
  349.  
  350. SlashCmdList.TOGGLE = function(msg, editBox)
  351.     print(WrapTextInColorCode("Below is a list of '/' commands to toggle hiding/showing respective frames.\n\n/castbarframe\n/buffsframe\n/debuffsframe\n/playerframe\n/focusframe\n/petframe\n/targetframe\n/raidframe\n/raidmanagerframe\n/partyframe\n/bossframe", "FF8C6FFF"))
  352. end
  353.  
  354. -- create options menu
  355.  
  356. local panel = CreateFrame("Frame")
  357. panel.name = "HideEverything"
  358. InterfaceOptions_AddCategory(panel)
  359.  
  360. local title = panel:CreateFontString("ARTWORK", nil, "GameFontNormalLarge")
  361. title:SetPoint("TOP")
  362. title:SetText("\n\nHideEverything\n\n\nBy default this addon hides all of the frames listed below.\nUse these '/' commands to toggle hiding and showing respective frames.\nEither toggle them with these buttons, directly in the chat, or make a macro.\nThe world is your oyster!\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nYou can also use '/he' or '/hideeverything' in\n the chat for a reminder of all of these.\n\nFYI: When the raid manager frame is hidden, the raid frame must be hidden as well.\n Additionally; after toggling either the raid frame or the raid manager frame \nyou must commit a '/reload' in order to see the changes take effect.\n\ndisclaimer1: When using this addon ensure other addons are not \nhiding the same frames, doing so could result in errors.\n\ndisclaimer2: You cannot toggle frames while in combat.\n An alert will be triggered in the chat if attempting to do so.")
  363.  
  364. local castbarbtn = CreateFrame("Button", nil, panel, "UIPanelButtonTemplate")
  365. castbarbtn.Text:SetText("/castbarframe")
  366. castbarbtn:SetPoint("TOPLEFT", 225, -160)
  367. castbarbtn:SetWidth(200)
  368. castbarbtn:HookScript("OnClick", function()
  369.     ToggleCastBarFrameFunc()
  370. end)
  371.  
  372. local buffbtn = CreateFrame("Button", nil, panel, "UIPanelButtonTemplate")
  373. buffbtn.Text:SetText("/buffsframe")
  374. buffbtn:SetPoint("TOPLEFT", 225, -180)
  375. buffbtn:SetWidth(200)
  376. buffbtn:HookScript("OnClick", function()
  377.     ToggleBuffFrameFunc()
  378. end)
  379.  
  380. local debuffbtn = CreateFrame("Button", nil, panel, "UIPanelButtonTemplate")
  381. debuffbtn.Text:SetText("/debuffsframe")
  382. debuffbtn:SetPoint("TOPLEFT", 225, -200)
  383. debuffbtn:SetWidth(200)
  384. debuffbtn:HookScript("OnClick", function()
  385.     ToggleDebuffFrameFunc()
  386. end)
  387.  
  388. local playerbtn = CreateFrame("Button", nil, panel, "UIPanelButtonTemplate")
  389. playerbtn.Text:SetText("/playerframe")
  390. playerbtn:SetPoint("TOPLEFT", 225, -220)
  391. playerbtn:SetWidth(200)
  392. playerbtn:HookScript("OnClick", function()
  393.      TogglePlayerFrameFunc()
  394. end)
  395.  
  396. local focusbtn = CreateFrame("Button", nil, panel, "UIPanelButtonTemplate")
  397. focusbtn.Text:SetText("/focusframe")
  398. focusbtn:SetPoint("TOPLEFT", 225, -240)
  399. focusbtn:SetWidth(200)
  400. focusbtn:HookScript("OnClick", function()
  401.     ToggleFocusFrameFunc()
  402. end)
  403.  
  404. local targetbtn = CreateFrame("Button", nil, panel, "UIPanelButtonTemplate")
  405. targetbtn.Text:SetText("/targetframe")
  406. targetbtn:SetPoint("TOPLEFT", 225, -260)
  407. targetbtn:SetWidth(200)
  408. targetbtn:HookScript("OnClick", function()
  409.     ToggleTargetFrameFunc()
  410. end)
  411.  
  412. local petbtn = CreateFrame("Button", nil, panel, "UIPanelButtonTemplate")
  413. petbtn.Text:SetText("/petframe")
  414. petbtn:SetPoint("TOPLEFT", 225, -280)
  415. petbtn:SetWidth(200)
  416. petbtn:HookScript("OnClick", function()
  417.     TogglePetFrameFunc()
  418. end)
  419.  
  420. local raidbtn = CreateFrame("Button", nil, panel, "UIPanelButtonTemplate")
  421. raidbtn.Text:SetText("/raidframe")
  422. raidbtn:SetPoint("TOPLEFT", 225, -300)
  423. raidbtn:SetWidth(200)
  424. raidbtn:HookScript("OnClick", function()
  425.     ToggleRaidFrameFunc()
  426. end)
  427.  
  428. local raidmanagerbtn = CreateFrame("Button", nil, panel, "UIPanelButtonTemplate")
  429. raidmanagerbtn.Text:SetText("/raidmanagerframe")
  430. raidmanagerbtn:SetPoint("TOPLEFT", 225, -320)
  431. raidmanagerbtn:SetWidth(200)
  432. raidmanagerbtn:HookScript("OnClick", function()
  433.     ToggleRaidManagerFrameFunc()
  434. end)
  435.  
  436. local partybtn = CreateFrame("Button", nil, panel, "UIPanelButtonTemplate")
  437. partybtn.Text:SetText("/partyframe")
  438. partybtn:SetPoint("TOPLEFT", 225, -340)
  439. partybtn:SetWidth(200)
  440. partybtn:HookScript("OnClick", function()
  441.     TogglePartyFrameFunc()
  442. end)
  443.  
  444. local bossbtn = CreateFrame("Button", nil, panel, "UIPanelButtonTemplate")
  445. bossbtn.Text:SetText("/bossframe")
  446. bossbtn:SetPoint("TOPLEFT", 225, -360)
  447. bossbtn:SetWidth(200)
  448. bossbtn:HookScript("OnClick", function()
  449.     ToggleBossFrameFunc()
  450. end)
  451.  
  452. --EOD
  Reply With Quote

WoWInterface » AddOns, Compilations, Macros » AddOn Help/Support » Can someone code review me?

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