I got a request from someone who wants to have a debuff filter removed for PvP/arena. Which made me ask myself if there is a way to "dynamically" change the filter (and maybe other things, too) based on the zone the player is in.
Which would be in this case PvP/BG zone OR else.
I checked Skada (because I remembered it has an option to hide in PvP) and it has the following function(s):
Code:
local wasininstance
local wasinpvp
-- Are we in a PVP zone?
local function is_in_pvp()
return select(2,IsInInstance()) == "pvp" or select(2,IsInInstance()) == "arena"
end
-- Fired on entering a zone.
function Skada:PLAYER_ENTERING_WORLD()
-- Check if we are entering an instance.
local inInstance, instanceType = IsInInstance()
local isininstance = inInstance and (instanceType == "party" or instanceType == "raid")
local isinpvp = is_in_pvp()
-- If we are entering an instance, and we were not previously in an instance, and we got this event before... and we have some data...
if isininstance and wasininstance ~= nil and not wasininstance and self.db.profile.reset.instance ~= 1 and total ~= nil then
if self.db.profile.reset.instance == 3 then
ask_for_reset()
else
self:Reset()
end
end
-- Hide in PvP. Hide if entering a PvP instance, show if we are leaving one.
if self.db.profile.hidepvp then
if is_in_pvp() then
Skada:SetActive(false)
elseif wasinpvp then
Skada:SetActive(true)
end
end
-- Save a flag marking our previous (current) instance status.
if isininstance then
wasininstance = true
else
wasininstance = false
end
-- Save a flag marking out previous (current) pvp status.
if isinpvp then
wasinpvp = true
else
wasinpvp = false
end
-- Mark our last party status. This is done so that the flag is set to correct value on relog/reloadui.
wasinparty = (GetNumPartyMembers() > 0 or GetNumRaidMembers() > 0)
-- Check for pets.
self:CheckPets()
end
Now, skada also checks if You are in a group or not, which is irrelevant (in our case, skada does this, because it also has an option to hide itself when solo).
Is it possible to adapt this for oUF? Is there an easier way to do code this? What's the best event to update the function (something like "onZoneChange" maybe)?