I can't remember if I asked this here before, but it's just something of an idle curiosity which I never managed to sate. I was making this addon where one of the things necessary to make it work well was simulating a UNIT_AURA event for all registered frames, to trick the frames in to thinking that a unit had received or lost a new aura. I think the problem I was encountering was figuring out the proper unitID. Even if I faked a UNIT_AURA event for the "target" UnitID, it wouldn't update, say, the focus frame, even if my focus WAS my target. Something like that.
Anyway, is there any way of simulating an event that's better than what I'm doing?
I'll just copy+paste the whole ugly lump of code I was using:
lua Code:
function FakeAuras_SimulateEvent(event, unit)
local frames = {GetFramesRegisteredForEvent(event)}
--God, I really have no idea how to do this in a better way. That's what I get for trying to support GUIDs and actual names.
if not UnitExists(unit) then
if unit == UnitName("target") or unit == UnitGUID("target") then
unit = "target"
elseif unit == UnitName("mouseover") or unit == UnitGUID("mouseover") then
unit = "mouseover"
elseif unit == UnitName("targettarget") or unit == UnitGUID("targettarget") then
unit = "targettarget"
elseif unit == UnitName("focus") or unit == UnitGUID("focus") then
unit = "focus"
elseif unit == UnitName("focustarget") or unit == UnitGUID("focustarget") then
unit = "focustarget"
else
unit = "player"
end
local s
for i=1,40 do
s = format(i<=4 and "party%s" or "raid%s",i)
if unit == UnitName(s) or unit == UnitGUID(s) then
unit = s
break
end
end
end
for _,frame in ipairs(frames) do
local f = function(u) frame:GetScript("OnEvent")(frame, event, u) end
--This is disgusting, but I have no idea how else to do it. I wish there was just some sort of SimulateEvent() API.
--This doesn't even begin to cover all the possibilities anyway :\
f("target")
f("player")
f("mouseover")
f("targettarget")
f("focus")
f("focustarget")
f(unit)
end
end
I'm not exactly sure why I had it setting unit to the target through focustarget things, when I just end up manually calling those UnitIDs anyway - possibly to avoid errors if I try to call a frame's event handler on an un-matched GUID or unit name. Don't quite remember. :\