View Single Post
09-23-14, 05:52 PM   #9
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
UnitName will return a valid value for the player unit immediately. However, UnitGUID won't return anything useful until PLAYER_LOGIN. Rather than calling these functions repeatedly in a combat log handler (which runs extremely frequently, and therefore adding 2 function calls there is extremely inefficient) you should register for PLAYER_LOGIN and initialize the variables there.

Also, I don't understand why you're checking the destination name instead of the destination GUID? Just check the GUID like you're doing with the source...

Code:
-- at the top:
local PlayerGUID

-- at the bottom:
local AnnounceFrame = CreateFrame("Frame")
AnnounceFrame:RegisterEvent("PLAYER_LOGIN")
AnnounceFrame:SetScript("OnEvent", function(self, event)
    PlayerGUID = UnitGUID("player")
    self:UnregisterEvent("PLAYER_LOGIN")
    self:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
    self:SetScript("OnEvent", OnEvent)
end)
The basic idea is that:

1. You only register for PLAYER_LOGIN at first.
2. When it fires, store the player's GUID, register for CLEU, and replace the OnEvent handler with the CLEU handler.
3. In the CLEU handler, refer to the stored GUID instead of looking up the same value over and over millions of times per play session.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.