WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Need help disabling an addon frame when out of combat (https://www.wowinterface.com/forums/showthread.php?t=58141)

ContactingWoWInterface 08-08-20 01:37 PM

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!

sezz 08-08-20 03:22 PM

why don't you use pitbull's combat fader instead or is this feature gone?

Xrystal 08-08-20 04:21 PM

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

ContactingWoWInterface 08-08-20 11:09 PM

Quote:

Originally Posted by sezz (Post 336557)
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.

Quote:

Originally Posted by Xrystal (Post 336558)
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?

Rilgamon 08-09-20 02:30 AM

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

ContactingWoWInterface 08-09-20 03:10 AM

Quote:

Originally Posted by Rilgamon (Post 336560)

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

Rilgamon 08-09-20 03:54 AM

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. ...

ContactingWoWInterface 08-09-20 05:54 AM

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.

Rilgamon 08-09-20 06:11 AM

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.

ContactingWoWInterface 08-09-20 06:31 AM

Quote:

Originally Posted by Rilgamon (Post 336564)
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.

Rilgamon 08-09-20 06:45 AM

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)

ContactingWoWInterface 08-09-20 08:44 AM

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.

ContactingWoWInterface 08-10-20 03:53 AM

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.

sezz 08-11-20 01:24 PM

Quote:

Originally Posted by ContactingWoWInterface (Post 336570)
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.


All times are GMT -6. The time now is 05:03 AM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI