View Single Post
12-09-12, 01:08 PM   #38
Billtopia
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Apr 2009
Posts: 110
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:
  1. -- Faction tooltip settings
  2.     local guidCache = {}
  3.     local utip = CreateFrame("GameTooltip", "uTip", UIParent, "GameTooltipTemplate")
  4.     utip:SetOwner( WorldFrame, "ANCHOR_NONE")
  5.  
  6.  
  7. -- Returns a faction from a given GUID for a player character
  8.     FactionByGUID = function(GUID)
  9.         uTip:ClearLines()
  10.         utip:SetHyperlink('unit:'..GUID)
  11.         if IsPlayerNeutral() then
  12.             return "Neutral"
  13.         end
  14.         if guidCache[GUID] then
  15.             return guidCache[GIUD]
  16.         end
  17.         local _, _, _, CompRace = GetPlayerInfoByGUID( GUID )
  18.         if CompRace ~= "Pandaren" then
  19.             local Alliance = { ["Worgen"] = true, ["Draenei"] = true, ["Dwarf"] = true, ["Gnome"] = true, ["Human"] = true, ["NightElf"] = true }
  20.             guidCache[GUID] = Alliance[CompRace] and FACTION_ALLIANCE or FACTION_HORDE
  21.             return guidCache[GUID]
  22.         end
  23.        
  24.         if GUID and tonumber(GUID:sub(5,5), 16) % 8 == 0 then
  25.             local tipName, numLines = "uTipTextLeft", _G["uTip"]:NumLines()
  26.             local faction = _G[tipName..tostring(numLines)]:GetText() == PVP and _G[tipName..tostring(numLines-1)]:GetText() or _G[tipName..tostring(numLines)]:GetText()
  27.             if faction ~= FACTION_ALLIANCE and faction ~= FACTION_HORDE then
  28.                 --compares level is too high so just invert our faction
  29.                 local _, myFaction = UnitFactionGroup('player')
  30.                 faction = myFaction == FACTION_ALLIANCE and FACTION_HORDE or FACTION_ALLIANCE
  31.             end
  32.             guidCache[GUID] = faction
  33.             return guidCache[GUID]
  34.         end
  35.     end

Last edited by Billtopia : 12-11-12 at 07:40 AM. Reason: adjusted some variable names
  Reply With Quote