View Single Post
Unread 12-04-12, 01:46 PM   #28
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 1,028
I'll have to do some further tests with the tooltips for the unit hyperlink. Previously, I've noticed it only returns useful data if the player in question is within the game client's visible range. If it does still work past that range, I might take a look into it and already have some optimizations in mind for the code.

Lua Code:
  1. local guidCache={};
  2. local ttframe=CreateFrame("GameTooltip","FactionIdentifierTooltip",nil,"GameTooltipTemplate");
  3. ttframe:SetOwner(WorldFrame,"ANCHOR_NONE");
  4.  
  5. function FactionGroupFromGUID(guid)
  6.     if guid and tonumber(guid:sub(5,5),16)%8==0 then
  7.         local faction=guidCache[guid];
  8.         if faction then return faction; end
  9.  
  10.         ttframe:ClearLines();
  11.         ttframe:SetHyperlink('unit:'..guid);
  12.         local lines=ttframe:NumLines();
  13.         local faction=_G["FactionIdentifierTooltipTextLeft"..tostring(lines)]:GetText();
  14.         if faction==PVP then faction=_G["FactionIdentifierTooltipTextLeft"..tostring(lines-1)]:GetText();
  15.  
  16.         if faction==FACTION_ALLIANCE or faction==FACTION_HORDE then
  17.             return faction==FACTION_ALLIANCE and "Alliance" or "Horde",faction;
  18.             guidCache[guid]=faction;--  Faction can change from Neutral to either of these
  19.         else
  20.             return "Neutral","";
  21.         end
  22.     else
  23.         return nil,nil;
  24.     end
  25. end

Assuming the tooltip works beyond the game client's visual range and no addons hook into the global metatable for tooltips, this modification should function in the same way UnitFactionGroup() does, but operate on GUIDs instead.
__________________
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)
SDPhantom is offline   Reply With Quote