Thread Tools Display Modes
03-16-10, 04:52 AM   #1
Santiclause
A Murloc Raider
AddOn Author - Click to view addons
Join Date: Aug 2008
Posts: 6
Simulating events

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:
  1. function FakeAuras_SimulateEvent(event, unit)
  2.    local frames = {GetFramesRegisteredForEvent(event)}
  3.    --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.
  4.    if not UnitExists(unit) then
  5.       if unit == UnitName("target") or unit == UnitGUID("target") then
  6.          unit = "target"
  7.       elseif unit == UnitName("mouseover") or unit == UnitGUID("mouseover") then
  8.          unit = "mouseover"
  9.       elseif unit == UnitName("targettarget") or unit == UnitGUID("targettarget") then
  10.          unit = "targettarget"
  11.       elseif unit == UnitName("focus") or unit == UnitGUID("focus") then
  12.          unit = "focus"
  13.       elseif unit == UnitName("focustarget") or unit == UnitGUID("focustarget") then
  14.          unit = "focustarget"
  15.       else
  16.          unit = "player"
  17.       end
  18.       local s
  19.       for i=1,40 do
  20.          s = format(i<=4 and "party%s" or "raid%s",i)
  21.          if unit == UnitName(s) or unit == UnitGUID(s) then
  22.             unit = s
  23.             break
  24.          end
  25.       end
  26.    end
  27.    for _,frame in ipairs(frames) do
  28.       local f = function(u) frame:GetScript("OnEvent")(frame, event, u) end
  29.       --This is disgusting, but I have no idea how else to do it. I wish there was just some sort of SimulateEvent() API.
  30.       --This doesn't even begin to cover all the possibilities anyway :\
  31.       f("target")
  32.       f("player")
  33.       f("mouseover")
  34.       f("targettarget")
  35.       f("focus")
  36.       f("focustarget")
  37.       f(unit)
  38.    end
  39. 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. :\

Last edited by Santiclause : 03-16-10 at 05:18 AM.
  Reply With Quote
03-16-10, 05:25 AM   #2
Rilgamon
Premium Member
 
Rilgamon's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Sep 2009
Posts: 822
Not sure if I understand you right. But your units listen to the events
and have a function set.

Code:
frame:SetScript("OnEvent", eventHandler)
Why not just call the eventHandler with the proper args ?

Something like

Code:
eventHandler(frame, event, unitid)
Edit: doh ... I misread your code. Now I see that you're doing this
__________________
The cataclysm broke the world ... and the pandas could not fix it!

Last edited by Rilgamon : 03-16-10 at 05:33 AM.
  Reply With Quote
03-16-10, 06:42 AM   #3
nightcracker
A Molten Giant
 
nightcracker's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2009
Posts: 716
If you're trying to transform an unit GUID to an unit ID I would suggest you take a look at my lib, LibGUIDMap. http://github.com/nightcracker/ncUI/...libguidmap.lua
__________________
Three things are certain,
Death, taxes and site not found,
You, victim of one.
  Reply With Quote
03-16-10, 02:36 PM   #4
Santiclause
A Murloc Raider
AddOn Author - Click to view addons
Join Date: Aug 2008
Posts: 6
The problem was that I wanted to make fake buffs or debuffs appear on unitframes or in your buff list or whatever. I seem to remember that as I was doing this, I thought that it'd be a simple matter to just loop through all the registered frames for UNIT_AURA, and call their event handlers with the given unitID. This didn't work, entirely. I mean, sure, if I sent "target" it would update the target unitframe, but it wouldn't update the targettarget, or the focus, or the player, or the focustarget, et cetera. I have no idea how the real UNIT_AURA events manage to update all the appropriate frames, and I'd like to know how it does (instead of this "throw ****ing EVERYTHING at it" approach that I'm using)
  Reply With Quote
03-16-10, 04:11 PM   #5
Shadowed
...
Premium Member
Featured
Join Date: Feb 2006
Posts: 387
Simulating events is ugly in general, especially if you are trying to simulate it on addons that you didn't make (Which is what you are doing from the sounds of it?). Addons monitor for specific units, and the game sends updates for each of those. If you focus then target yourself, you'll get 3 sets of aura events, one for player, target, focus. If you want to simulate an event you have to essentially fire it for all the real units: player, pet, focus, target, arena#, party#, raid#, raidpet#, think I missed a few more.
  Reply With Quote
03-16-10, 04:28 PM   #6
Santiclause
A Murloc Raider
AddOn Author - Click to view addons
Join Date: Aug 2008
Posts: 6
Originally Posted by Shadowed View Post
Simulating events is ugly in general, especially if you are trying to simulate it on addons that you didn't make (Which is what you are doing from the sounds of it?). Addons monitor for specific units, and the game sends updates for each of those. If you focus then target yourself, you'll get 3 sets of aura events, one for player, target, focus. If you want to simulate an event you have to essentially fire it for all the real units: player, pet, focus, target, arena#, party#, raid#, raidpet#, think I missed a few more.


Yeah, the game sends updates for each of them - but how does it KNOW which ones are necessary? If I could just figure that out, it would be better, I think.
  Reply With Quote
03-17-10, 09:37 AM   #7
Shadowed
...
Premium Member
Featured
Join Date: Feb 2006
Posts: 387
Originally Posted by Santiclause View Post
Yeah, the game sends updates for each of them - but how does it KNOW which ones are necessary? If I could just figure that out, it would be better, I think.
The event system is "dumb," all it does is fire events that frames registered for. You could only use UNIT_AURA updates from the player, and you'll get events for every other unit's aura update, which is why you have to always check what unit fired an unit event before processing to make sure it's the one you want.
  Reply With Quote
03-17-10, 11:11 AM   #8
nightcracker
A Molten Giant
 
nightcracker's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2009
Posts: 716
If you want to fire an event for every single frame, use EnumerateFrames().
__________________
Three things are certain,
Death, taxes and site not found,
You, victim of one.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Simulating events


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off