That's pretty inefficient, too, with numerous unnecessary extra functions and checks. I also have no idea why you're ignoring all events that occur in combat. I'd say the vast majority of totem drops/deaths/recalls occur in combat. It looks like the OP is trying to write a totem timer, which does not involve any secure frames.
Lua Code:
-- First, check if the player is a shaman.
-- If not, then we don't need to do anything else.
local _, class = UnitClass("player")
if class ~= "SHAMAN" then return end
local frame = CreateFrame("Frame")
frame:RegisterEvent("PLAYER_ENTERING_WORLD")
-- Unless you actually care whether the player is in combat or not, you
-- do not need to listen for these two events:
frame:RegisterEvent("PLAYER_REGEN_DISABLED")
frame:RegisterEvent("PLAYER_REGEN_ENABLED")
-- Unless you actually care how much mana the player has, you should
-- probably listen for PLAYER_TOTEM_UPDATE instead of UNIT_POWER.
frame:RegisterEvent("UNIT_POWER")
frame:SetScript("OnEvent", function(self, event, unit, resource)
-- Of the events you are watching, only UNIT_POWER passes any
-- arguments (or fires for units other than the player), so make
-- sure we're not responding to other units' power update events.
if event == "UNIT_POWER" and (unit ~= "player" or resource ~= "MANA") then return end
-- Check if the player has ANY totem active.
local hasTotem
for i = 1, 4 do
local _, name = GetTotemInfo(i)
if name and name:len() > 0 then
hasTotem = true
break
end
end
-- Do things here depending on whether or not a totem is active.
if hasTotem then
self:Show() -- Inside this scope, "self" refers to the frame.
else
self:Hide()
end
end)