Thread Tools Display Modes
08-15-10, 05:28 PM   #1
Waky
A Cobalt Mageweaver
 
Waky's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2010
Posts: 200
Help with COMBAT_LOG_EVENT_UNFILTERED

I'm trying to create an addon that will be able to tell you when you cast Focus Magic on someone.

This is my XML (<Scripts>...</Scripts>):
Code:
		<Scripts>
			<OnLoad>
				wFM_OnLoad();
			</OnLoad>
			<OnEvent>
				wFM_OnEvent(event, ...);
			</OnEvent>
			<OnMouseDown>
				wFM_OnMouseDown();
			</OnMouseDown>
			<OnMouseUp>
				wFM_OnMouseUp();
			</OnMouseUp>
		</Scripts>
This is my OnLoad that's referred to in XML, as you can see my wFM_MainFrame is set to Register the combat log event.
Code:
function wFM_OnLoad()

	wFM_MainFrame:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED");
	
	return;
end --OnLoad
and finally this is my OnEvent:
Code:
function wFM_OnEvent(event, ...)
  local timestamp, type, sourceGUID, sourceName, sourceFlags, destGUID, destName, destFlags, spellId, spellName = select(1, ...)
  
   if event == "COMBAT_LOG_EVENT_UNFILTERED" and type == "SPELL_CAST_SUCCESS" then
		if spellId == 54646 then
			DEFAULT_CHAT_FRAME:AddMessage(""..sourceName.." has cast Focus magic");
		end
	end
end --OnEvent
Basically when I cast Focus Magic it should say "Waky has cast Focus Magic" in my chat frame, but it keeps returning sourceName as nil.

Can anyone tell me what's wrong with this code?

Any help would be appreciated, this is my first attempt at an AddOn (besides Hello World! :P)
  Reply With Quote
08-15-10, 05:41 PM   #2
Starinnia
Ninja Code Monkey
AddOn Author - Click to view addons
Join Date: Apr 2007
Posts: 84
Code:
local timestamp, type, sourceGUID, sourceName, sourceFlags, destGUID, destName, destFlags, spellId, spellName = select(1, ...)
Should just be
Code:
local timestamp, type, sourceGUID, sourceName, sourceFlags, destGUID, destName, destFlags, spellId, spellName = ...
The call to select(1, ...) only returns the first value from the vararg.
  Reply With Quote
08-15-10, 05:55 PM   #3
Waky
A Cobalt Mageweaver
 
Waky's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2010
Posts: 200
Thanks for responding so quickly!

That sure sounded like it would work, but nothing still . Did you notice anything else that could be wrong?
  Reply With Quote
08-15-10, 06:06 PM   #4
Starinnia
Ninja Code Monkey
AddOn Author - Click to view addons
Join Date: Apr 2007
Posts: 84
You could try changing your XML file

Code:
		<Scripts>
			<OnLoad>
				wFM_OnLoad();
			</OnLoad>
			<OnEvent function="wFM_OnEvent"/>
			<OnMouseDown>
				wFM_OnMouseDown();
			</OnMouseDown>
			<OnMouseUp>
				wFM_OnMouseUp();
			</OnMouseUp>
		</Scripts>

Not 100% sure that will change anything since I've never used XML frame creation, but its worth a try.
  Reply With Quote
08-15-10, 06:31 PM   #5
Waky
A Cobalt Mageweaver
 
Waky's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2010
Posts: 200
No go I don't want to sound ungrateful lol, but any other ideas?
  Reply With Quote
08-15-10, 06:34 PM   #6
Soulofsin_007
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Apr 2008
Posts: 125
Code:
local eventframe = CreateFrame("FRAME")
eventframe:SetPoint("CENTER")
eventframe:SetScript("OnEvent", function(self, event, ...)
  local timestamp, type, sourceGUID, sourceName, sourceFlags, destGUID, destName, destFlags = select(1, ...)
  
    if event == "COMBAT_LOG_EVENT_UNFILTERED" then
    if (type=="SPELL_AURA_APPLIED") then

      local spellId, spellName, spellSchool = select(9, ...)
  
      if (spellName=="Focus Magic") then 
        DEFAULT_CHAT_FRAME:AddMessage(destName.." has focus magic");
     end
   end
 end
end)
eventframe:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
Edit: The above works, I just tested it out in game.

Last edited by Soulofsin_007 : 08-15-10 at 06:55 PM.
  Reply With Quote
08-15-10, 07:35 PM   #7
Waky
A Cobalt Mageweaver
 
Waky's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2010
Posts: 200
The only thing about that one Soul is that it doesn't use the XML frames like I am.
  Reply With Quote
08-15-10, 08:48 PM   #8
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
You don't need to use XML.

In any case, you didn't quite set up your event handler correctly. The first return in OnEvent is a reference to the frame that is registered to that event and triggered the function. The second return is the event name itself, then followed by any returns that come with that event (all the info on CLU).
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
08-17-10, 12:36 AM   #9
Waky
A Cobalt Mageweaver
 
Waky's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2010
Posts: 200
Alrighty, I decided to use Soul's method and it worked perfectly, thanks very much!
  Reply With Quote
08-17-10, 04:32 PM   #10
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by Starinnia View Post
The call to select(1, ...) only returns the first value from the vararg.
That's actually incorrect. select(n, ...) returns the nth value and all subsequent values.

So, if you have:

Code:
local a, b, c, d, e, f, g = GetSomeValues()
But you didn't care about a or b, you could do:

Code:
local c, d, e, f, g = select(3, GetSomeValues())
Though it would be slightly faster to do:

Code:
local _, _, c, d, e, f, g = GetSomeValues()
The real value of select lies in the fact that normally this:

Code:
if GetSomeValues() == "x" then
...would compare the first return value (the one assigned to a in the first example) against the string "x", but we can use select to compare against, say, e instead:

Code:
if select(5, GetSomeValues()) == "x" then
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Help with COMBAT_LOG_EVENT_UNFILTERED


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