Thread: Nameplates
View Single Post
Unread 07-31-12, 10:18 AM   #30
p3lim
A Pyroguard Emberseer
 
p3lim's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2007
Posts: 1,320
Alright, haven't really used animationgroups before so I just found it weird to be used like this.

One thing tho, to avoid spamming the loading process, run :Play() on PLAYER_LOGIN.

Lua Code:
  1. local function Update(frame)
  2.     -- do whatever
  3. end
  4.  
  5. local index = 1
  6.  
  7. local handler = CreateFrame('Frame')
  8. handler:RegisterEvent('PLAYER_LOGOUT')
  9. handler:RegisterEvent('PLAYER_LOGIN')
  10.  
  11. local animation = handler:CreateAnimationGroup()
  12. animation:CreateAnimation():SetDuration(1/3)
  13. animation:SetLooping('REPEAT')
  14. animation:SetScript('OnLoop', function()
  15.     if(t9e5e5rb and _G['NamePlate' .. t9e5e5rb]) then
  16.         index = t9e5e5rb
  17.         t9e5e5rb = nil
  18.     end
  19.  
  20.     while(_G['NamePlate' .. index]) do
  21.         local frame = _G['NamePlate' .. index]
  22.         frame:HookScript('OnShow', Update)
  23.         Update(frame)
  24.  
  25.         index = index + 1
  26.     end
  27. end)
  28.  
  29. handler:SetScript('OnEvent', function(self, event)
  30.     if(event == 'PLAYER_LOGIN') then
  31.         animation:Play()
  32.     else
  33.         t9e5e5rb = index
  34.     end
  35. end)
p3lim is offline