Well, I don't know about the general idea, but these parts will definitely
not work while in combat. You will get "action blocked" errors and the default action bars may even stop working.
Code:
ChangeActionBarPage(1)
ActionBarUpButton:Disable()
ActionBarDownButton:Disable()
_G["ExtraBarButton"..i]:Show()
_G["ExtraBarButton"..i]:Hide()
You
can't hide, show, or disable secure/protected frames while in combat, and you
can't change action bar pages while in combat,
except in response to specific Blizzard-approved conditions (eg. the same ones you can check for in a macro) and using specific Blizzard-approved secure methods.
On top of that, using an OnUpdate script to hide things in combat is quite possibly
the most inefficient way to do that. Here is a better way:
Code:
local f = CreateFrame("Frame") -- or use the one you already have
f:RegisterEvent("PLAYER_REGEN_DISABLED")
f:RegisterEvent("PLAYER_REGEN_ENABLED")
f:SetScript("OnEvent", function(self, event, ...) -- or add to the one you already have
if InCombatLockdown() then return end -- safety check, not needed if frames are insecure
SOME_OTHER_FRAME:SetShown(not UnitAffectingCombat("player")) -- hide OOC, remove "not" to show OOC instead
end)
This should work for both secure and insecure frames, since when PLAYER_REGEN_DISABLED fires to indicate entering combat, the UI isn't yet locked down, to allow addons to make changes beforehand, and when PLAYER_REGEN_ENABLED to indicate leaving combat, the UI lockdown has already been released.
Your other option would be to use a state driver:
Code:
local f = CreateFrame("Frame", "MyCombatHider", UIParent, "SecureHandlerStateTemplate")
f:SetAllPoints(true) -- not *really* needed but makes child placement easier
RegisterStateDriver(self, "visibility", "[combat] hide; show")
-- parent your other frames to MyCombatHider instead of UIParent
For swapping actionbar pages, you just can't automate that. While in combat, a hardware event (key press or mouse click) is required to change pages.
Disabling the pageup/down buttons should be safe, but only if you do it out of combat. There's no need to wait for ADDON_LOADED; you can just do it in the main chunk.