View Single Post
10-25-19, 10:51 PM   #3
Kanegasi
A Molten Giant
 
Kanegasi's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2007
Posts: 666
Don't worry, you're fine. I wasn't attacking you, just informing you. You don't need UnitGUID to get a player's GUID from chat, it comes in the 12th argument in chat event payloads. It's how that cvar I mentioned works in the UI code.

Lua Code:
  1. function ChatClassColorOverrideShown()
  2.     local value = GetCVar("chatClassColorOverride");
  3.     if value == "0" then
  4.         return true;
  5.     elseif value == "1" then
  6.         return false;
  7.     else
  8.         return nil;
  9.     end
  10. end
  11.  
  12. function Chat_ShouldColorChatByClass(chatTypeInfo)
  13.     local override = ChatClassColorOverrideShown();
  14.     local colorByClass = chatTypeInfo and chatTypeInfo.colorNameByClass;
  15.     return override or (override == nil and colorByClass);
  16. end
  17.  
  18. function GetColoredName(event, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12)
  19. -- truncate...
  20.     if ( arg12 and info and Chat_ShouldColorChatByClass(info) ) then
  21.         local localizedClass, englishClass, localizedRace, englishRace, sex = GetPlayerInfoByGUID(arg12)
  22.  
  23.         if ( englishClass ) then
  24.             local classColorTable = RAID_CLASS_COLORS[englishClass];
  25.             if ( not classColorTable ) then
  26.                 return arg2;
  27.             end
  28.             return string.format("\124cff%.2x%.2x%.2x", classColorTable.r*255, classColorTable.g*255, classColorTable.b*255)..arg2.."\124r"
  29.         end
  30.     end
  31. -- truncate...
  32. end

GetColoredName is called every single time ChatFrame_MessageEventHandler is called. Also, as long as any event gives you the GUID, it will return usable values, no matter who the player is. It's a universal solution for every player your UI interacts with. You're right about the cache thing, but there's no point in asking for info about an offline player or a player you don't see anywhere in the UI anyways.

Last edited by Kanegasi : 10-25-19 at 10:54 PM.
  Reply With Quote