Quantcast
Need help disabling an addon frame when out of combat - WoWInterface
Thread Tools Display Modes
08-08-20, 01:37 PM   #1
ContactingWoWInterface
A Murloc Raider
Join Date: Aug 2020
Posts: 8
Need help disabling an addon frame when out of combat

I apologize if this isn't the right place to post this, I wasn't sure if I should post here or under AddOn Search/Requests. I've been trying to modify this script and I've been running into a few issues. While my chosen frame is disabled once combat is finished, it doesn't disable the frame when I log in until after I exit combat. This is my modified version.


Lua Code:
  1. local f = CreateFrame("Frame")
  2. local inCombat = false --need own variable becuase of event timings
  3. f:RegisterEvent("PLAYER_REGEN_DISABLED") -- entered combat
  4. f:RegisterEvent("PLAYER_REGEN_ENABLED") -- left combat
  5. f:SetScript("OnEvent", function(self, event, ...) -- hides/shows frames when leaving/entering combat
  6.     if event =="PLAYER_REGEN_DISABLED" then
  7.         inCombat = true
  8.         PitBull4_Groups_Party:Show()
  9.     else
  10.         inCombat = false
  11.         PitBull4_Groups_Party:Hide()
  12.     end
  13. end)
  14. PitBull4_Groups_Party:Hide() -- hides frames when client has loaded
  15. --Make sure frames stay hidden while out of combat
  16. PitBull4_Groups_Party:SetScript("OnShow",
  17. function()
  18.     if (inCombat == false) then
  19.         PitBull4_Groups_Party:Hide()
  20.     end
  21. end)

When logging in I get the following error:

Lua Code:
  1. 1x !PitBull4_Combat_Toggle\core.lua:16: attempt to index global 'PitBull4_Groups_Party' (a nil value)
  2. [string "@!PitBull4_Combat_Toggle\core.lua"]:16: in main chunk
  3.  
  4. Locals:
  5. f = <unnamed> {
  6.  0 = <userdata>
  7. }
  8. inCombat = false
  9. (*temporary) = nil
  10. (*temporary) = nil
  11. (*temporary) = "OnEvent"
  12. (*temporary) = <function> defined @!PitBull4_Combat_Toggle\core.lua:5
  13. (*temporary) = "attempt to index global 'PitBull4_Groups_Party' (a nil value)"

After speaking with some others I've come to the conclusion that this most likely happens because this script is loading before Pitbull (the addon that contains the frame I'm hiding). My best guess would be that the original author didn't have this issue since he was hiding blizzard frames. I'd assume those load before everything else. It seems like "ADDON_LOADED" may be able to make this script load after Pitbull, but I'm not quite sure how to implement it. I assume that this error is tied together with the reason that my frame isn't hiding prior to exiting combat.

Lastly, in the forum post where I originally found this script (the one linked at the top) the author adds a feature that fades the frames in and out. If possible, I'd like to add that feature to this script but again I'm not sure how to go about doing that. I know that Pitbull has a built in feature to control fading in and out of combat, but it doesn't prevent the frame from being clicked. While it does have a "click through" option, that applies to all frames and I don't want that.

To sum things up:
1. I'd like my script to disable the "PitBull4_Groups_Party" frame while not in combat but an error is preventing this on login.
2. I'd like the frame to fade in and out prior to being disabled.

This is the first time I've tried to do something like this and I'm definitely in over my head. I've looked/asked around and I've tried to do my best to figure things out, but I've been at this for a day or two with no success. Most of the material I've been looking at has been from WoW Interface so I thought it would be a good idea to ask here. Any help would be greatly appreciated because I'm at a loss!
  Reply With Quote
08-08-20, 03:22 PM   #2
sezz
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Apr 2008
Posts: 131
why don't you use pitbull's combat fader instead or is this feature gone?
  Reply With Quote
08-08-20, 04:21 PM   #3
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,513
ADDON_LOADED event has one parameter .. the name of the addon ..

So, first, identify the precise addon name for Pitbull . Then in the if statement for testing whether the addon loaded is pitbull .. do your pitbull required functionality then.

This is an example from one of my nUI plugins. I check for both nUI and my own addon.. If this was a plugin that included a third addon window I would check for that as well and make sure all required addons are loaded once the plugin addon is loaded ..
Lua Code:
  1. local addonName, addon = ...
  2.     local function onEvent(self,event,arg1,arg2,arg3)
  3.         if ( event == "ADDON_LOADED" ) then
  4.             if arg1 == "nUI" then
  5.                 addon.nUILoaded = true
  6.             elseif arg1 == addonName then
  7.                 if not addon.nUILoaded then
  8.                     LoadAddOn("nUI")
  9.                 end
  10.                 addon.nUILoaded = IsAddOnLoaded("nUI")
  11.                 addon.plugin = plugin
  12.                 addon:OnAddonLoaded()
  13.             end
  14.         end
  15.     end
__________________
  Reply With Quote
08-08-20, 11:09 PM   #4
ContactingWoWInterface
A Murloc Raider
Join Date: Aug 2020
Posts: 8
Originally Posted by sezz View Post
why don't you use pitbull's combat fader instead or is this feature gone?
Pitbull has a built in feature to control fading in and out of combat, but it doesn't prevent the frame from being clicked. While it does have a "click through" option, that applies to all frames and I don't want that.

Originally Posted by Xrystal View Post
ADDON_LOADED event has one parameter .. the name of the addon ..

So, first, identify the precise addon name for Pitbull . Then in the if statement for testing whether the addon loaded is pitbull .. do your pitbull required functionality then.

This is an example from one of my nUI plugins. I check for both nUI and my own addon.. If this was a plugin that included a third addon window I would check for that as well and make sure all required addons are loaded once the plugin addon is loaded ..
Lua Code:
  1. local addonName, addon = ...
  2.     local function onEvent(self,event,arg1,arg2,arg3)
  3.         if ( event == "ADDON_LOADED" ) then
  4.             if arg1 == "nUI" then
  5.                 addon.nUILoaded = true
  6.             elseif arg1 == addonName then
  7.                 if not addon.nUILoaded then
  8.                     LoadAddOn("nUI")
  9.                 end
  10.                 addon.nUILoaded = IsAddOnLoaded("nUI")
  11.                 addon.plugin = plugin
  12.                 addon:OnAddonLoaded()
  13.             end
  14.         end
  15.     end

Thank you for the example. I'm going to mess around with this and see if I can make something work. If you don't mind me asking, at which point in this script is it checking for your own addon?

Last edited by ContactingWoWInterface : 08-08-20 at 11:58 PM.
  Reply With Quote
08-09-20, 02:30 AM   #5
Rilgamon
Premium Member
 
Rilgamon's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Sep 2009
Posts: 789
A shorter version would be telling wow to load your addon after the addon you depend on.

https://wow.gamepedia.com/TOC_format

OptionalDeps
String - A comma-separated list of addon (directory) names that should be loaded before this addon if they can be loaded.
Code:
## OptionalDeps: someAddOn, someOtherAddOn
__________________
The cataclysm broke the world ... and the pandas could not fix it!
  Reply With Quote
08-09-20, 03:10 AM   #6
ContactingWoWInterface
A Murloc Raider
Join Date: Aug 2020
Posts: 8
Originally Posted by Rilgamon View Post

OptionalDeps
String - A comma-separated list of addon (directory) names that should be loaded before this addon if they can be loaded.
Code:
## OptionalDeps: someAddOn, someOtherAddOn
When I add "## OptionalDeps: PitBull4" to my .toc file I get this error.

Lua Code:
  1. 2x PitBull4_Combat_Toggle\core.lua:14: attempt to index global 'PitBull4_Groups_Party' (a nil value)
  2. [string "@PitBull4_Combat_Toggle\core.lua"]:14: in main chunk
  3.  
  4. Locals:
  5. f = <unnamed> {
  6.  0 = <userdata>
  7. }
  8. inCombat = false
  9. (*temporary) = nil
  10. (*temporary) = nil
  11. (*temporary) = "OnEvent"
  12. (*temporary) = <function> defined @PitBull4_Combat_Toggle\core.lua:5
  13. (*temporary) = "attempt to index global 'PitBull4_Groups_Party' (a nil value)"

Does this mean that it isn't related to the load order? From my understanding a nil value means that it doesn't exist for it to use, but the frame is clearly there when I log in. If it isn't load order I'm lost. T_T
  Reply With Quote
08-09-20, 03:54 AM   #7
Rilgamon
Premium Member
 
Rilgamon's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Sep 2009
Posts: 789
I dont use Pitbull but I see that it has a modular setup.
Looking at the code I'd guess it is created on startup. But only when the group is enabled (dont know what that means in this context).

In the Main.lua the function OnProfileChanged calls MakeGroupHeader which is located in GroupHeader.lua . So my guess would be that the group 'party' is not enabled when you try to access it.
Lua Code:
  1. function PitBull4:OnProfileChanged()
  2. ...
  3.     for group, group_db in pairs(db.profile.groups) do
  4.         if group_db.enabled then
  5.             self:MakeGroupHeader(group)
  6.             for header in PitBull4:IterateHeadersForName(group) do
  7.                 header.group_db = group_db
  8.                 header:RefreshGroup()
  9.                 header:UpdateShownState()
  10.             end
  11.         end
  12.     end
  13. ...
__________________
The cataclysm broke the world ... and the pandas could not fix it!
  Reply With Quote
08-09-20, 05:54 AM   #8
ContactingWoWInterface
A Murloc Raider
Join Date: Aug 2020
Posts: 8
Finally I made some progress. I'm pretty sure I made things a ton harder than they should have been, but it's nice to go from knowing absolutely nothing to seeing something work. As I mentioned above, I added the ## OptionalDeps: PitBull4 to my .toc but it didn't change anything. At first I thought that I was wrong about the nil value error, but then I wondered if Pitbull needed some time to load its frames after its own activation. I did a little poking around and figured out how to implement C_Timer.After. Stalling the script a little seems to have done the trick. Now I just need to fix it from reappearing when I change specs / implement some kind of fader.
  Reply With Quote
08-09-20, 06:11 AM   #9
Rilgamon
Premium Member
 
Rilgamon's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Sep 2009
Posts: 789
Keep in mind that some changes cant be made in combat. That means the change has to be made before you receive the combat event. So when you reload in a combat situation your script might fail because it tries it too late.
__________________
The cataclysm broke the world ... and the pandas could not fix it!
  Reply With Quote
08-09-20, 06:31 AM   #10
ContactingWoWInterface
A Murloc Raider
Join Date: Aug 2020
Posts: 8
Originally Posted by Rilgamon View Post
Keep in mind that some changes cant be made in combat. That means the change has to be made before you receive the combat event. So when you reload in a combat situation your script might fail because it tries it too late.
That's a very valid point, I hadn't thought of that. Could you suggest a way to change it before a combat event?

Edit: Luckily after some testing it seems that reloading during combat doesn't interfere with with the script.

Last edited by ContactingWoWInterface : 08-09-20 at 08:40 AM.
  Reply With Quote
08-09-20, 06:45 AM   #11
Rilgamon
Premium Member
 
Rilgamon's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Sep 2009
Posts: 789
Not sure. I'm not good with the secure handling of scripts.
I'd either track down exactly the events that lead to the construction of the frame and copy them
or I'd add checks if the frame exists before I use it which is always a good idea when you dont own a frame.

Lua Code:
  1. frameHandler:SetScript("OnEvent", function(self, event, ...) -- Hides/shows frames when leaving/entering combat
  2.   if PitBull4_Groups_Party then  
  3.     if event =="PLAYER_REGEN_DISABLED" then
  4.         inCombat = true
  5.         PitBull4_Groups_Party:Show()
  6.     else
  7.         inCombat = false
  8.         PitBull4_Groups_Party:Hide()
  9.     end
  10.   end
  11. end)
__________________
The cataclysm broke the world ... and the pandas could not fix it!
  Reply With Quote
08-09-20, 08:44 AM   #12
ContactingWoWInterface
A Murloc Raider
Join Date: Aug 2020
Posts: 8
I'm not sure that I went about this the best way, but here's what I've managed to get so far. I'm sure something will go wrong, but in the meantime this script seems to disable the frame at login, after combat has ended and after I change talents (frame only activates for holy spec).

Lua Code:
  1. local frameHandler = CreateFrame("FRAME")
  2. local frameHandler2 = CreateFrame("FRAME")
  3. local inCombat = false -- Need own variable becuase of event timings
  4.  
  5. frameHandler:SetScript("OnEvent", function(self, event, ...) -- Hides/shows frames when leaving/entering combat
  6.     if event =="PLAYER_REGEN_DISABLED" then
  7.         inCombat = true
  8.         PitBull4_Groups_Party:Show()
  9.     else
  10.         inCombat = false
  11.         PitBull4_Groups_Party:Hide()
  12.     end
  13.     if IsAddOnLoaded("PitBull4") then
  14.         C_Timer.After(0.1, function()
  15.         PitBull4_Groups_Party:Hide()
  16.         end)
  17.     end
  18. end)
  19.  
  20. frameHandler2:SetScript("OnEvent", function(self, event, ...) -- Hides/shows frames when changing talent specialization
  21.     if event =="ACTIVE_TALENT_GROUP_CHANGED" then
  22.         C_Timer.After(0.1, function()
  23.         PitBull4_Groups_Party:Hide()
  24.         end)
  25.     end
  26. end)
  27.  
  28. frameHandler:RegisterEvent("PLAYER_REGEN_ENABLED") -- Left combat
  29. frameHandler:RegisterEvent("PLAYER_REGEN_DISABLED") -- Entered combat
  30. frameHandler2:RegisterEvent("ACTIVE_TALENT_GROUP_CHANGED") -- Changed talent specialization

Now I need to figure out how to make the frame fade before it goes away.

Last edited by ContactingWoWInterface : 08-09-20 at 08:53 AM.
  Reply With Quote
08-10-20, 03:53 AM   #13
ContactingWoWInterface
A Murloc Raider
Join Date: Aug 2020
Posts: 8
I'm currently trying to use UIFrameFade to hide the frames. UIFrameFadeIn works fine but when I try to use iUIFrameFadeOut I get an ADDON_ACTION_BLOCKED error. I'm not sure why I can hide the frame but not fade it out. Any suggestions would be appreciated.
  Reply With Quote
08-11-20, 01:24 PM   #14
sezz
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Apr 2008
Posts: 131
Originally Posted by ContactingWoWInterface View Post
I'm currently trying to use UIFrameFade to hide the frames. UIFrameFadeIn works fine but when I try to use iUIFrameFadeOut I get an ADDON_ACTION_BLOCKED error. I'm not sure why I can hide the frame but not fade it out. Any suggestions would be appreciated.
Hide works, but when you change it to UIFrameFadeOut it causes issues?

Blizzards fading has caused taints in the past, maybe the problem still exists.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Need help disabling an addon frame when out of combat

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