As the first return of GetTotemInfo is wether a totem exists or not, you don't have to check names.
The cleanest and most efficent way to do this is so:
Lua Code:
if(select(2, UnitClass('player')) ~= 'SHAMAN') then return end
local addon = CreateFrame('Frame')
addon:RegisterEvent('PLAYER_REGEN_ENABLED')
addon:RegisterEvent('PLAYER_TOTEM_UPDATE')
addon:SetScript('OnEvent', function(self)
local hasTotem
for index = 1, 4 do
if(GetTotemInfo(index)) then
hasTotem = true
break
end
end
if(hasTotem) then
self:Show()
else
self:Hide()
end
end)
You can check for each totem if you'd like, through the 1st argument in PLAYER_TOTEM_UPDATE.
I made a simple totem tracking addon for my shaman about a year ago, take a look if you want:
https://github.com/p3lim/Devak/blob/master/Devak.lua