Thread Tools Display Modes
01-23-17, 03:10 PM   #41
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,877
If you're getting two entries/panels in the Addons menu, you have doubled up on the code either in another addon or you've got two copies in the same addon (possibly pasted one after the other in the same file).
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 01-23-17 at 03:13 PM.
  Reply With Quote
01-23-17, 04:54 PM   #42
wille480
A Wyrmkin Dreamwalker
Join Date: Jan 2017
Posts: 56
Originally Posted by Fizzlemizz View Post
If you're getting two entries/panels in the Addons menu, you have doubled up on the code either in another addon or you've got two copies in the same addon (possibly pasted one after the other in the same file).
yes! remade all files and now it does not create 2 panels
Still the code for when you get the debuff now does not work.

This is the whole code
Lua Code:
  1. local TaintOfTheSea     = GetSpellInfo(228054)
  2. local Ticker            = 0
  3. local MoveMessage       = "{moon} MOVE TO MOON {moon}"
  4. local DispelMessage     = "Dispell on {moon} in "
  5. local debuffexists      = false
  6. local titleFont = [=[Interface\Addons\HelyaAssist\fonts\accid___.ttf]=]
  7. local folder = "HelyaAssist"
  8. local ds = 0
  9.  
  10. -- Adds HelyaAssist to interface in addons
  11. local myAddon = {};
  12. myAddon.panel = CreateFrame( "Frame", "myAddonPanel", UIParent);
  13. myAddon.panel.name = "HelyaAssist";
  14. InterfaceOptions_AddCategory(myAddon.panel);
  15.  
  16. --Text in panel
  17. local MOD_TextFrame = CreateFrame("Frame", nil, myAddonPanel);
  18. MOD_TextFrame:ClearAllPoints();
  19. MOD_TextFrame:SetHeight(300);
  20. MOD_TextFrame:SetWidth(300);
  21. MOD_TextFrame:SetScript("OnUpdate", MOD_TextFrame_OnUpdate);
  22. MOD_TextFrame.text = MOD_TextFrame:CreateFontString(nil, "BACKGROUND", "PVPInfoTextFont");
  23. MOD_TextFrame.text:SetAllPoints();
  24. MOD_TextFrame:SetPoint("CENTER", -245, 260);
  25. MOD_TextFrameTime = 0;
  26. MOD_TextFrame.text:SetText('|cffffff00HelyaAssist');
  27. MOD_TextFrame.text:SetFont(titleFont, 19);
  28.  
  29. --Create the button (enable)
  30. local buttonEnable = CreateFrame("Button","mybutton", myAddon.panel, "UIPanelButtonTemplate")
  31. buttonEnable:SetPoint("CENTER", -255,220)
  32. buttonEnable:SetWidth(80)
  33. buttonEnable:SetHeight(22)
  34. buttonEnable:SetText("Enabled")
  35.  
  36. --If buttonEnable is clicked , then Enable HelyaAssist (enable button)
  37. buttonEnable:SetScript("OnClick", function(self, button, down)
  38. local playerName = UnitName("player")
  39.     HelyaAssistAddon.disabled = nil
  40.     HelyaAssistAddon.shown = nil
  41.     ReloadUI()
  42. end)
  43.  
  44. --Create the button (disable)
  45. local buttonDisable = CreateFrame("Button","mybutton", myAddon.panel, "UIPanelButtonTemplate")
  46. buttonDisable:SetPoint("CENTER", -160,220)
  47. buttonDisable:SetWidth(80)
  48. buttonDisable:SetHeight(22)
  49. buttonDisable:SetText("Disabled")
  50.  
  51. --If buttonDisable is clicked, then disable HelyaAssist (disable button)
  52. buttonDisable:SetScript("OnClick", function(self, button, down)
  53.     local playerName = UnitName("player")
  54.     HelyaAssistAddon.disabled = true
  55.     HelyaAssistAddon.shown = nil
  56.     ReloadUI()
  57. end)
  58.  
  59.  
  60. local function UpdateTicker()
  61.     if Ticker < 1 or not debuffexists then return end
  62.     SendChatMessage((Ticker > 5) and MoveMessage or DispelMessage .. Ticker, "Yell", nil, name)
  63.     Ticker = Ticker - 1
  64.     C_Timer.After((Ticker > 5) and 1.5 or 0.7, UpdateTicker)
  65. end
  66.  
  67. local frame = CreateFrame("FRAME", "FooAddonFrame");
  68.  
  69. function frame:UNIT_AURA()
  70.     local name, _, _, _, _, duration, expires = UnitDebuff("player", TaintOfTheSea)
  71.     if name then
  72.         if not debuffexists then
  73.             debuffexists = true --player just got the debuff
  74.             Ticker = 6
  75.             UpdateTicker()
  76.         end
  77.     else
  78.         debuffexists = false -- doesn't exist
  79.     end
  80. end
  81.  
  82. function frame:PLAYER_ENTERING_WORLD(event, ...)
  83.     if not HelyaAssistAddon then
  84.         HelyaAssistAddon = {}
  85.     end
  86.     local playerName = UnitName("player")
  87.     if HelyaAssistAddon.disabled then
  88.         if not HelyaAssistAddon.shown then
  89.             HelyaAssistAddon.shown = true
  90.             print('|cffffff00HelyaAssist is now Disabled')
  91.         end
  92.         MOD_TextFrame:Hide()
  93.         buttonEnable:Enable()
  94.         buttonDisable:Disable()
  95.     else
  96.         if not HelyaAssistAddon.shown then
  97.             HelyaAssistAddon.shown = true
  98.             print('|cffffff00HelyaAssist is now Enable')
  99.         end
  100.         buttonDisable:Enable()
  101.         buttonEnable:Disable()
  102.         self:RegisterUnitEvent("UNIT_AURA", "player")
  103.         self:SetScript("OnEvent", UNIT_AURA)
  104.     end
  105.     self:UnregisterEvent("PLAYER_ENTERING_WORLD")
  106. end
  107.  
  108. frame:SetScript("OnEvent", function(self, event, ...)
  109.         self[event](self, event, ...)
  110.     end)
  111. frame:RegisterEvent("PLAYER_ENTERING_WORLD");
Even if it is set to Disable or Enable through buttons it will not do that function with "MOVE TO MOON" message and the dispell counter.
This code below is only for the debuff with move to moon message and dispell counter
Lua Code:
  1. local TaintOfTheSea     = GetSpellInfo(228054)
  2. local Ticker            = 0
  3. local MoveMessage       = "{moon} MOVE TO MOON {moon}"
  4. local DispelMessage     = "Dispell on {moon} in "
  5. local debuffexists      = false
  6.  
  7. local function UpdateTicker()
  8.     if Ticker < 1 or not debuffexists then return end
  9.  
  10.     SendChatMessage((Ticker > 5) and MoveMessage or DispelMessage .. Ticker, "Yell", nil, name)
  11.     Ticker = Ticker - 1
  12.  
  13.     C_Timer.After((Ticker > 5) and 1.5 or 0.4, UpdateTicker)
  14. end
  15.  
  16. local function UNIT_AURA()
  17.     local name, _, _, _, _, duration, expires = UnitDebuff("player", TaintOfTheSea)
  18.    
  19.     if name then
  20.         if not debuffexists then
  21.             debuffexists = true --player just got the debuff
  22.             Ticker = 6
  23.             UpdateTicker()
  24.         end
  25.     else
  26.         debuffexists = false -- doesn't exist
  27.     end
  28. end
  29.  
  30. local eventframe = CreateFrame("Frame")
  31. eventframe:RegisterUnitEvent("UNIT_AURA", "player")
  32. eventframe:SetScript("OnEvent", UNIT_AURA)
best regards

Last edited by wille480 : 01-23-17 at 04:58 PM.
  Reply With Quote
01-23-17, 05:33 PM   #43
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,877
Delete the line:
Code:
self:SetScript("OnEvent", UNIT_AURA)
I missed it and it's actually stopping OnEvent processing (setting it to nil) because the function UNIT_AURA no longer exists, my bad.
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.
  Reply With Quote
01-23-17, 05:41 PM   #44
wille480
A Wyrmkin Dreamwalker
Join Date: Jan 2017
Posts: 56
Oh hehe got it!
Everyone miss stuff with programming, atleast me , just want to get in with more lua. I am very used to c# and do that alot but this was abit different!

I will test the code out tomorrow and see if deleting the line will fix it, pretty sure it will^^
Ty for help so far fizzle, you rock
  Reply With Quote
01-23-17, 08:28 PM   #45
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,877
Just for good measure, I re-did the code and incorporated the pas06 additions.

It SHOULD (the in raid code is untested):
Only start UNIT_AURA event checking when entering the Helya encounter (raid).
Enabling/Disabling no longer require a ReloadUI (hence the print has been moved).
Enabling/Disabling now occurs per character.
Enabling/Disabling during the raid will have no effect until the next time the raid starts (exit, re-enter/reload/login) (this could be changed by moving the test to the UNIT_AURA function).
The first time you enter the raid each session (login/ReloadUI), or after enabling/disabling in the same session, with the addon disabled, a disabled message is printed. You will have to exit the raid to "enable" the addon.

Lua Code:
  1. local TaintOfTheSea     = GetSpellInfo(228054)
  2. local Ticker            = 0
  3. local MoveMessage       = "{moon} MOVE TO MOON {moon}"
  4. local DispelMessage     = "Dispell on {moon} in "
  5. local debuffexists      = false
  6. local titleFont = [=[Interface\Addons\HelyaAssist\fonts\accid___.ttf]=]
  7. local profile
  8.  
  9. local function SetEnabled(self)
  10.     if HelyaAssistAddon[profile].disabled then
  11.         self.buttonEnable:Enable()
  12.         self.buttonDisable:Disable()
  13.     else
  14.         self.buttonEnable:Disable()
  15.         self.buttonDisable:Enable()
  16.     end
  17. end
  18.  
  19. -- Adds HelyaAssist to interface in addons
  20. local myAddon = {};
  21. myAddon.panel = CreateFrame( "Frame", "HelyaAssistAddonPanel", UIParent);
  22. myAddon.panel.name = "HelyaAssist";
  23. InterfaceOptions_AddCategory(myAddon.panel);
  24.  
  25. myAddon.panel.text = myAddon.panel:CreateFontString("$parent_Text", "BACKGROUND", "PVPInfoTextFont");
  26. myAddon.panel.text:SetPoint("CENTER", -245, 260);
  27. myAddon.panel.text:SetFont(titleFont, 19);
  28. myAddon.panel.text:SetText('|cffffff00HelyaAssist');
  29.  
  30. --Create the button (enable)
  31. myAddon.panel.buttonEnable = CreateFrame("Button","$parent_Enablebutton", myAddon.panel, "UIPanelButtonTemplate")
  32. myAddon.panel.buttonEnable:SetPoint("CENTER", -255,220)
  33. myAddon.panel.buttonEnable:SetWidth(80)
  34. myAddon.panel.buttonEnable:SetHeight(22)
  35. myAddon.panel.buttonEnable:SetText("Enabled")
  36.  --If buttonEnable is clicked , then Enable HelyaAssist (enable button)
  37. myAddon.panel.buttonEnable:SetScript("OnClick", function(self, button, down)
  38.     HelyaAssistAddon[profile].disabled = nil
  39.     SetEnabled(self:GetParent())
  40. end)
  41.  
  42. --Create the button (disable)
  43. myAddon.panel.buttonDisable = CreateFrame("Button","$parent_Disablebutton", myAddon.panel, "UIPanelButtonTemplate")
  44. myAddon.panel.buttonDisable:SetPoint("CENTER", -160,220)
  45. myAddon.panel.buttonDisable:SetWidth(80)
  46. myAddon.panel.buttonDisable:SetHeight(22)
  47. myAddon.panel.buttonDisable:SetText("Disabled")
  48.  --If buttonDisable is clicked, then disable HelyaAssist (disable button)
  49. myAddon.panel.buttonDisable:SetScript("OnClick", function(self, button, down)
  50.     HelyaAssistAddon[profile].disabled = true
  51.     HelyaAssistAddon[profile].shown = nil
  52.     SetEnabled(self:GetParent())
  53. end)
  54.  
  55. ----------------------------------------
  56. --    The event (start-up and in-raid) code starts here
  57. ----------------------------------------
  58. local function UpdateTicker()
  59.     if Ticker < 1 or not debuffexists then return end
  60.     SendChatMessage((Ticker > 5) and MoveMessage or DispelMessage .. Ticker, "Yell", nil, name)
  61.     Ticker = Ticker - 1
  62.     C_Timer.After((Ticker > 5) and 1.5 or 0.7, UpdateTicker)
  63. end
  64.  
  65. -- Create the event frame
  66. local frame = CreateFrame("Frame", "HelyaAssistEventFrame");
  67.  
  68. -- Add the event functions to the frame.
  69. function frame.ENCOUNTER_END(self)
  70.     self:UnregisterEvent("UNIT_AURA")
  71.     self:UnregisterEvent("ENCOUNTER_END")
  72. end
  73.  
  74. function frame.ENCOUNTER_START(self, event, encounterID)
  75.     if encounterID == 1829 then
  76.         if HelyaAssistAddon[profile].disabled then
  77.             if not HelyaAssistAddon[profile].shown then
  78.                 HelyaAssistAddon[profile].shown = true
  79.                 print('HelyaAssistAddon is disabled!')
  80.             end
  81.             return
  82.         end
  83.         self:RegisterUnitEvent("UNIT_AURA", "player")
  84.         self:RegisterEvent("ENCOUNTER_END")
  85.     end
  86. end
  87.  
  88. -- Initilise the SavedVariable information for each character if required
  89. -- (saving character-realm makes sure it's unique if you have
  90. -- characters with the same name on different realms)
  91. function frame.PLAYER_LOGIN(self)
  92.     if not HelyaAssistAddon then
  93.         HelyaAssistAddon = {}
  94.     end
  95.     local playerName = UnitName("player")
  96.     profile = playerName .. " - " .. GetRealmName()
  97.     if not HelyaAssistAddon[profile] then
  98.         HelyaAssistAddon[profile] = {}
  99.     end
  100.     SetEnabled(HelyaAssistAddonPanel)
  101.     HelyaAssistAddon[profile].shown = nil
  102.     self:RegisterEvent("ENCOUNTER_START")
  103. end
  104.  
  105. function frame.UNIT_AURA()
  106.     local name, _, _, _, _, duration, expires = UnitDebuff("player", TaintOfTheSea)
  107.     if name then
  108.         if not debuffexists then
  109.             debuffexists = true --player just got the debuff
  110.             Ticker = 6
  111.             UpdateTicker()
  112.         end
  113.     else
  114.         debuffexists = false -- doesn't exist
  115.     end
  116. end
  117.  
  118. -- Set the OnEvent script to use the frame.event (self[event]) functions
  119. frame:SetScript("OnEvent", function(self, event, ...)
  120.         self[event](self, event, ...)
  121.     end)
  122.  
  123. ----------------------------------------
  124. -- Get it all started. The PLAYER_LOGIN event fires after all addons are loaded
  125. -- and before PLAYER_ENTERING_WORLD and only fires once and also has
  126. -- the required information available to initialise the profile variable.
  127. ----------------------------------------
  128. frame:RegisterEvent("PLAYER_LOGIN");

As an aside, frame "names" when they are created also become global references so you need to make sure they are unique if you are specifically naming them ("myAddon", "foo...", "frame" etc. are not good names).

If you leave the name as nil, the game generates a uniquie id. for the name (good for frames you won't need to access in your code but will be un-informative when using /fstack).

Prefixing $parent to the widget(frame etc.) name, and passing the parent widget(frame etc.) to CreateFrame, prefixes the parent widget name to the child:

Lua Code:
  1. local parentFrame = CreateFrame("Frame", "UberUniquiName")
  2. --parentFrame name is UberUniquiName
  3.  
  4. parentFrame.otherFrame = CreateFrame("Frame", "$parent_CoolName", parentFrame)
  5. --parentFrame.otherFrame name is UberUniquiName_CoolName
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 01-24-17 at 12:12 AM.
  Reply With Quote

WoWInterface » AddOns, Compilations, Macros » AddOn Help/Support » button("OnClick") & PLAYER_ENTERING_WORLD


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