OK... So here is what I have now. It will return Neutral when the player is neutral, as you can only run into neutral players then, it tests the race of all chars and figures out by that, faction, except for pandas which it uses the tooltip. I combined how I was originally testing and incorporated the tooltip for scanning pandas only.
Lua Code:
-- Faction tooltip settings
local guidCache = {}
local utip = CreateFrame("GameTooltip", "uTip", UIParent, "GameTooltipTemplate")
utip:SetOwner( WorldFrame, "ANCHOR_NONE")
-- Returns a faction from a given GUID for a player character
FactionByGUID = function(GUID)
uTip:ClearLines()
utip:SetHyperlink('unit:'..GUID)
if IsPlayerNeutral() then
return "Neutral"
end
if guidCache[GUID] then
return guidCache[GIUD]
end
local _, _, _, CompRace = GetPlayerInfoByGUID( GUID )
if CompRace ~= "Pandaren" then
local Alliance = { ["Worgen"] = true, ["Draenei"] = true, ["Dwarf"] = true, ["Gnome"] = true, ["Human"] = true, ["NightElf"] = true }
guidCache[GUID] = Alliance[CompRace] and FACTION_ALLIANCE or FACTION_HORDE
return guidCache[GUID]
end
if GUID and tonumber(GUID:sub(5,5), 16) % 8 == 0 then
local tipName, numLines = "uTipTextLeft", _G["uTip"]:NumLines()
local faction = _G[tipName..tostring(numLines)]:GetText() == PVP and _G[tipName..tostring(numLines-1)]:GetText() or _G[tipName..tostring(numLines)]:GetText()
if faction ~= FACTION_ALLIANCE and faction ~= FACTION_HORDE then
--compares level is too high so just invert our faction
local _, myFaction = UnitFactionGroup('player')
faction = myFaction == FACTION_ALLIANCE and FACTION_HORDE or FACTION_ALLIANCE
end
guidCache[GUID] = faction
return guidCache[GUID]
end
end