sure beats the following... this is what I was doing before, modified for the SendAddonMessage and to catch the thrown error if it happens
if it is passed just a GUID it will return true if the person is part of your faction or if you are a panda
if you pass a GUID, and a function to run if true / false and char name and unlimited args for the passed functions ... if a non panda it will automatically call the proper function (if it exists) and return true/false depending... if a panda it queues up the required info in a table, sends the addon message and waits up to 1 second for the error. if the error is thrown, it will call the ifFalse function and remove the panda from the queue... after the 1 second, the addon calls the ifTrue function if supplied and then removes the panda from the queue
it will call ifTrue/ifFalse with GUID, unpack(...)
Lua Code:
local pandaQueue = {}
local pandaE = 0
local pandaDelay = 1
local pandaCheckFrame = CreateFrame("Frame","pandaCheckFrame", UIParent)
pandaCheckFrame:SetScript("onUpdate",function( self, elapsed )
pandaE = pandaE + elapsed
if pandaE < 1/10 then
return
end
local e = pandaE
local count = #pandaQueue
pandaE = 0
if count == 0 then
return
end
for x = count, 1, -1 do
pandaQueue[x].time = pandaQueue[x].time + e
if pandaQueue[x].time > pandaDelay then
if type( pandaQueue[x].ifTrue ) == "function" then
pandaQueue[x].ifTrue( pandaQueue[x].GUID, pandaQueue[x].event, unpack( pandaQueue[x] ) )
end
table.remove( pandaQueue, x )
return true
end
end
end)
local pandaFilter = function( self, event, ... )
if #pandaQueue == 0 then
return false
end
local arg = {...}
for x = #pandaQueue, 1, -1 do
if arg[1] == string.format(ERR_CHAT_PLAYER_NOT_FOUND_S, pandaQueue[x].name ) then
if type( pandaQueue[x].ifFalse ) == "function" then
pandaQueue[x].ifFalse( pandaQueue[x].GUID, unpack( pandaQueue[x] ) )
end
table.remove( pandaQueue, x )
return true
end
end
return false
end
ChatFrame_AddMessageEventFilter("CHAT_MSG_SYSTEM", pandaFilter)
SameFaction = function( GUID, ifTrue, ifFalse, name, ... )
local isSame = false
local _, _, _, CompRace = GetPlayerInfoByGUID( GUID )
CompRace = string.lower(CompRace)
if IsPlayerNeutral() then
isSame = true
elseif CompRace == "pandaren" then
if type( ifTrue ) == "function" or type( ifFalse ) == "function" then
local index = #pandaQueue + 1
pandaQueue[index] = { unpack(...) }
pandaQueue[index].GUID = GUID
pandaQueue[index].ifTrue = ifTrue
pandaQueue[index].ifFalse = ifFalse
pandaQueue[index].name = name
pandaQueue[index].time = 0
SendAddonMessage("FactionTest", "Pandaren Faction Test", "whisper", name)
return true
else
isSame = true
end
else
local PlayerIsAlliance = UnitFactionGroup("player") == "Alliance"
local Allies = { ["worgen"] = true, ["draenei"] = true, ["dwarf"] = true, ["gnome"] = true, ["human"] = true, ["nightelf"] = true }
local CompIsAlliance = Allies[CompRace] and true or false
if PlayerIsAlliance == CompIsAlliance then
isSame = true
end
end
if isSame then
if type( ifTrue ) == "function" then
ifTrue( GUID, unpack(...))
end
return true
end
if type( ifFalse ) == "function" then
ifFalse( GUID, unpack(...))
end
return false
end