View Single Post
12-02-12, 08:56 AM   #15
semlar
A Pyroguard Emberseer
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 1,060
Here'a a "quick" and dirty method for getting the faction from a unit's GUID using its tooltip:
Lua Code:
  1. local guidCache = {}
  2. local _, myFaction = UnitFactionGroup('player')
  3. local utip = CreateFrame("GameTooltip", "uTip", UIParent, "GameTooltipTemplate")
  4.  
  5. local function DoSomething(guid)
  6.     local faction = guidCache[guid]
  7.     if faction then
  8.         print(guid, faction, faction == myFaction)
  9.     end
  10. end
  11.  
  12. utip:SetScript("OnTooltipSetUnit", function(self)
  13.     if guidCache[self.guid] then return end
  14.     local tipName, numLines = self:GetName()..'TextLeft', self:NumLines()
  15.     local faction = _G[tipName..numLines]:GetText() == PVP and _G[tipName..(numLines-1)]:GetText() or _G[tipName..numLines]:GetText()
  16.     guidCache[self.guid] = faction
  17.     DoSomething(self.guid)
  18. end)
  19.  
  20. function ScanFaction(guid)
  21.     if guid and tonumber(guid:sub(5,5), 16) % 8 == 0 then
  22.         if guidCache[guid] then
  23.             DoSomething(guid)
  24.         else
  25.             utip.guid = guid
  26.             utip:SetHyperlink('unit:'..guid)
  27.         end
  28.     end
  29. end
Usage: ScanFaction(UnitGUID('example')), calls DoSomething when it's finished.

Probably not the best solution but maybe it'll help somebody.

Last edited by semlar : 12-02-12 at 02:51 PM.
  Reply With Quote