View Single Post
01-03-12, 06:43 AM   #11
p3lim
A Pyroguard Emberseer
 
p3lim's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2007
Posts: 1,710
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:
  1. if(select(2, UnitClass('player')) ~= 'SHAMAN') then return end
  2.  
  3. local addon = CreateFrame('Frame')
  4. addon:RegisterEvent('PLAYER_REGEN_ENABLED')
  5. addon:RegisterEvent('PLAYER_TOTEM_UPDATE')
  6. addon:SetScript('OnEvent', function(self)
  7.     local hasTotem
  8.  
  9.     for index = 1, 4 do
  10.         if(GetTotemInfo(index)) then
  11.             hasTotem = true
  12.             break
  13.         end
  14.     end
  15.  
  16.     if(hasTotem) then
  17.         self:Show()
  18.     else
  19.         self:Hide()
  20.     end
  21. 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
  Reply With Quote