Thread Tools Display Modes
05-14-11, 10:42 AM   #1
swordbeta
A Murloc Raider
Join Date: Oct 2009
Posts: 4
Combat log, can't get damage

So, I'm relative new to LUA and I was just messing around with the combat log. I'm unable to get the amount of damage, while there is. According to: http://www.wowpedia.org/API_COMBAT_LOG_EVENT this is the 13th parameter, but it seems like it's not working and I'm not sure what I'm doing wrong. When replacing the variable dmg with "test" it works, so it has to be "local dmg = select(12, ...)".

Can anyone point me into the right direction?

Code:
local DTPStext = CreateFrame("frame")

DTPStext:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
DTPStext:SetScript("OnEvent", function(this, event, ...) DTPStext[event](...) end)
DEFAULT_CHAT_FRAME:AddMessage("DTPStext: Loaded")

function DTPStext.COMBAT_LOG_EVENT_UNFILTERED(self, event, ...)
	local destGUID = select(6, ...)
	if(string.match(event, "DAMAGE")) then --this is damage!
		if(destGUID==UnitName("player")) then --this is me!
			local dmg = select(12, ...)
			DEFAULT_CHAT_FRAME:AddMessage(dmg)
		end
	end
end
EDIT: Okay, this is rather weird. Whenever taking damage from another playing, local dmg = select(11, ...) works. However when taking falling damage (environmental) ět returns 1.

Last edited by swordbeta : 05-14-11 at 10:52 AM.
  Reply With Quote
05-14-11, 02:38 PM   #2
Rilgamon
Premium Member
 
Rilgamon's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Sep 2009
Posts: 822
destGuid should be 7th value.
You should pass on all args or give them the right names.
Your varargs (...) start with the timestamp followed by the event.
__________________
The cataclysm broke the world ... and the pandas could not fix it!
  Reply With Quote
05-14-11, 02:44 PM   #3
tinyu
A Molten Giant
 
tinyu's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 837
shouldnt

Code:
DTPStext:SetScript("OnEvent", function(this, event, ...)
be

Code:
DTPStext:SetScript("OnEvent", function(self, event, ...)
?
__________________
"There's no such thing as too many addons."
Lothaer
Titan Dev Team Member.
  Reply With Quote
05-14-11, 03:23 PM   #4
Ketho
A Pyroguard Emberseer
 
Ketho's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,026
ENVIRONMENTAL_DAMAGE is a bit wierd in that the Environmental Type (arg10) moves everything else 1 position up.
So the damage amount you're looking for would be at arg11

.. Let's just say that your whole function is a mess and that everything inside should be killed with fire
The event handler you are using is good for registering multiple events. If you actually know where your parameters are
Code:
local DTPStext = CreateFrame("Frame")
DTPStext:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
DTPStext:SetScript("OnEvent", function(self, event, ...)
	DTPStext[event](self, ...)
end)

function DTPStext:COMBAT_LOG_EVENT_UNFILTERED(...)
	local _, subevent, _, _, _, _, _, destName = ...
	local amount

	if strfind(subevent, "DAMAGE") and destName == UnitName("player") then
		local prefix = strsub(subevent, 1, 5)
		if prefix == "SWING" then
			amount = select(10, ...)
		elseif subevent == "ENVIRONMENTAL_DAMAGE" then
			amount = select(11, ...)
		elseif prefix == "SPELL" or prefix == "RANGED" then
			amount = select(13, ...)
		end

		print("I got damaged for "..amount, subevent)
	end
end

Last edited by Ketho : 05-15-11 at 02:47 PM.
  Reply With Quote
05-14-11, 03:44 PM   #5
swordbeta
A Murloc Raider
Join Date: Oct 2009
Posts: 4
Thanks a bunch all, especially Ketho!
While you're here anyway, is there an equivalent of 'setTimeout' of js in LUA?

Last edited by swordbeta : 05-14-11 at 03:46 PM.
  Reply With Quote
05-14-11, 07:45 PM   #6
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
Originally Posted by tinyu View Post
shouldnt

Code:
DTPStext:SetScript("OnEvent", function(this, event, ...)
be

Code:
DTPStext:SetScript("OnEvent", function(self, event, ...)
?
No. It could be
Code:
DTPStext:SetScript("OnEvent", function(myFrame, stuffHappens, ...)
if you want.
__________________
"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
05-15-11, 03:40 AM   #7
Torhal
A Pyroguard Emberseer
 
Torhal's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2008
Posts: 1,196
To expound on what Seerah said: In that snippet, the word "this" was simply a parameter name - not the now-removed global "this".
__________________
Whenever someone says "pls" because it's shorter than "please", I say "no" because it's shorter than "yes".

Author of NPCScan and many other AddOns.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Combat log, can't get damage


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