View Single Post
08-08-20, 01:37 PM   #1
ContactingWoWInterface
A Deviate Faerie Dragon
Join Date: Aug 2020
Posts: 12
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