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:
local guidCache={};
local ttframe=CreateFrame("GameTooltip","FactionIdentifierTooltip",nil,"GameTooltipTemplate");
ttframe:SetOwner(WorldFrame,"ANCHOR_NONE");
function FactionGroupFromGUID(guid)
if guid and tonumber(guid:sub(5,5),16)%8==0 then
local faction=guidCache[guid];
if faction then return faction; end
ttframe:ClearLines();
ttframe:SetHyperlink('unit:'..guid);
local lines=ttframe:NumLines();
local faction=_G["FactionIdentifierTooltipTextLeft"..tostring(lines)]:GetText();
if faction==PVP then faction=_G["FactionIdentifierTooltipTextLeft"..tostring(lines-1)]:GetText();
if faction==FACTION_ALLIANCE or faction==FACTION_HORDE then
return faction==FACTION_ALLIANCE and "Alliance" or "Horde",faction;
guidCache[guid]=faction;-- Faction can change from Neutral to either of these
else
return "Neutral","";
end
else
return nil,nil;
end
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.