Thread Tools Display Modes
04/20/14, 11:46 PM   #1
mikethecoder4
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 13
Detecting Deaths

Hey there. New to Addon creating, but not to LUA or programming in general. So i had a question that I havent been able to find an answer for through research and searches. Im basically trying to make an addon that will tell me if I get a player kill or not. To start, i decided to try to make it detect when I kill anything. When I was testing on my low level character, I got it to count my kills on NPCs successfully by registering the EVENT_UNIT_DEATH_STATE_CHANGED event. However, when I went to test this on my main character in Cyrodil, killing NPCs and other mobs didnt increase the counter at all. I checked the event log using the zgoo addon (which is how i found out about the death state changed event above) and that event doesnt seem to be firing. In fact, I cant seem to find any event that happens when something does (to signify the death event I mean. of course theres xp and a bunch of other events)

Is there any way to reliably test for deaths or hook an event to them? Also is there a way to tell if they are player deaths or not?

Here is my Lua code in case its necessary
Code:
local counter = 0
 
function MyFirstAddOnUpdate()
    KillCounter_Kills:SetText(string.format("Kills: %d", counter))
end

function OnKill(eventCode, arg1, arg2)
    --print the inviter's name to chat
    counter = counter + 1
    d(arg1)
    d(arg2)
end

function OnInitialized(self)
    --Register on the top level control...
    EVENT_MANAGER:RegisterForEvent("KillCounter", EVENT_UNIT_DEATH_STATE_CHANGED, OnKill)
 	
 	SLASH_COMMANDS["/kcreset"] = function (extra)
 		-- reset counter
  		counter = 0
	end
end
 
04/21/14, 12:06 AM   #2
BadVolt
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 74
Originally Posted by mikethecoder4 View Post
Hey there. New to Addon creating, but not to LUA or programming in general. So i had a question that I havent been able to find an answer for through research and searches. Im basically trying to make an addon that will tell me if I get a player kill or not. To start, i decided to try to make it detect when I kill anything. When I was testing on my low level character, I got it to count my kills on NPCs successfully by registering the EVENT_UNIT_DEATH_STATE_CHANGED event. However, when I went to test this on my main character in Cyrodil, killing NPCs and other mobs didnt increase the counter at all. I checked the event log using the zgoo addon (which is how i found out about the death state changed event above) and that event doesnt seem to be firing. In fact, I cant seem to find any event that happens when something does (to signify the death event I mean. of course theres xp and a bunch of other events)

Is there any way to reliably test for deaths or hook an event to them? Also is there a way to tell if they are player deaths or not?

Here is my Lua code in case its necessary
Code:
local counter = 0
 
function MyFirstAddOnUpdate()
    KillCounter_Kills:SetText(string.format("Kills: %d", counter))
end

function OnKill(eventCode, arg1, arg2)
    --print the inviter's name to chat
    counter = counter + 1
    d(arg1)
    d(arg2)
end

function OnInitialized(self)
    --Register on the top level control...
    EVENT_MANAGER:RegisterForEvent("KillCounter", EVENT_UNIT_DEATH_STATE_CHANGED, OnKill)
 	
 	SLASH_COMMANDS["/kcreset"] = function (extra)
 		-- reset counter
  		counter = 0
	end
end
Looks like you didn't initialized your addon. You have to register an event that will fire OnInitialized(self).
Lua Code:
  1. EVENT_MANAGER:RegisterForEvent("KillCounter", EVENT_ADD_ON_LOADED, OnInitialized)

And make filter for OnInitialized function. You don't want to trigger this event each time any addon loads, don't you?
Lua Code:
  1. function OnInitialized(eventCode, addOnName)
  2.    If addOnName~="KillCounter" then return end
  3.    ...
  4. end

Or you initialised your addon from XML file (self parameter makes me think like that) and I'm wrong
Elso you have wrong params list in function OnKill. Event EVENT_UNIT_DEATH_STATE_CHANGED have 2 args: unitTag,isDead. So, you have to work with them.
Lua Code:
  1. function OnKill(unitTag, isDead)
  2.    If unitTag==GetUnitName("player") and isDead then
  3.    ...
  4.    end
  5. end
If nothing works, you can check EVENT_PLAYER_DEAD param. It can have some args, so may be interested to check them.. but to info on WIKI about it.

Last edited by BadVolt : 04/21/14 at 12:10 AM.
 
04/21/14, 08:46 AM   #3
Garkin
 
Garkin's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 832
Originally Posted by BadVolt View Post
Elso you have wrong params list in function OnKill. Event EVENT_UNIT_DEATH_STATE_CHANGED have 2 args: unitTag,isDead. So, you have to work with them.
Lua Code:
  1. function OnKill(unitTag, isDead)
  2.    If unitTag==GetUnitName("player") and isDead then
  3.    ...
  4.    end
  5. end
If nothing works, you can check EVENT_PLAYER_DEAD param. It can have some args, so may be interested to check them.. but to info on WIKI about it.
In this case is wiki wrong, all events has "eventCode" as a first argument, so mikethecoder4's OnKill() function was correct.
 
04/21/14, 09:01 AM   #4
BadVolt
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 74
Originally Posted by Garkin View Post
In this case is wiki wrong, all events has "eventCode" as a first argument, so mikethecoder4's OnKill() function was correct.
Nice to know. Thanks.
 
04/21/14, 09:06 AM   #5
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Feb 2014
Posts: 648
Well... The wiki isn't wrong. The event itself really does have only 2 returns. But the event handler passes along the event code along with the two returns from the event.
 
04/21/14, 09:08 AM   #6
Iyanga
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 183
Originally Posted by Seerah View Post
Well... The wiki isn't wrong.
Or maybe the wiki is wrong and you just don't want to accept it.
 
04/21/14, 11:47 AM   #7
mikethecoder4
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 13
Originally Posted by BadVolt View Post
Looks like you didn't initialized your addon. You have to register an event that will fire OnInitialized(self).
Lua Code:
  1. EVENT_MANAGER:RegisterForEvent("KillCounter", EVENT_ADD_ON_LOADED, OnInitialized)

And make filter for OnInitialized function. You don't want to trigger this event each time any addon loads, don't you?
Lua Code:
  1. function OnInitialized(eventCode, addOnName)
  2.    If addOnName~="KillCounter" then return end
  3.    ...
  4. end

Or you initialised your addon from XML file (self parameter makes me think like that) and I'm wrong
Elso you have wrong params list in function OnKill. Event EVENT_UNIT_DEATH_STATE_CHANGED have 2 args: unitTag,isDead. So, you have to work with them.
Lua Code:
  1. function OnKill(unitTag, isDead)
  2.    If unitTag==GetUnitName("player") and isDead then
  3.    ...
  4.    end
  5. end
If nothing works, you can check EVENT_PLAYER_DEAD param. It can have some args, so may be interested to check them.. but to info on WIKI about it.
Hey there, thanks for the reply! Didnt know about the filtering! and yes, I call the OnInitialize function from my xml.

Like some people have said, the event has the eventCode varaible passed as well as the other two (args 1 and 2 in my function)

The event actually does WORK, but only in stonefalls (based on my testing so far) with my level 3 character on not in Cyrodil with my v1 character.

I will look into this EVENT_PLAYER_DEAD event, see if it helps.

Thanks for the advice!

Edit: Wiki doesn't seem to list the events for EVENT_PLAYER_DEAD. I'll have a look into zgoo once ESO patches to see if I can find them out, but until then, does anyone know what the arguments are?

Last edited by mikethecoder4 : 04/21/14 at 11:53 AM.
 
04/21/14, 01:20 PM   #8
mikethecoder4
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 13
I mayu have figured it out.

I used to EVENT_COMBAT_EVENT event, and did the following

Code:
function OnKill( eventCode , result , isError , abilityName, abilityGraphic, abilityActionSlotType, sourceName, sourceType, targetName, targetType, hitValue, powerType, damageType, log )

	if result == ACTION_RESULT_KILLING_BLOW then
		--d("Works")
		counter = counter + 1
	end
end
I registered the combat event like so

Code:
EVENT_MANAGER:RegisterForEvent("KillCounter", EVENT_PLAYER_DEAD, OnKilled)
Gonna keep testing to make sure it works. Thanks all for the help, I'll let you guys know if i confirm it works.


EDIT: Nope, not quite but ALMOST THERE. This event definitely procs when killing blows and such happen, but are not limited to the players killing blows it seems. Will report with progress as I figure this out. Need to figure out these arguments. For many of the events, alot of the arguments are empty, so its hard to find out their values without looking through like a million of them.

Last edited by mikethecoder4 : 04/21/14 at 01:30 PM.
 
04/21/14, 01:31 PM   #9
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Feb 2014
Posts: 648
Check the source name against your name.
 
04/21/14, 01:41 PM   #10
mikethecoder4
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 13
Originally Posted by Seerah View Post
Check the source name against your name.
Thanks for advice! I actually literally just took a wayshrine to test just this. I am wondering if this will only track killing blows, and not kills that you get credit for (IE kills that count towards the cyrodil quest)

Well if I can get killing blows to work I will be happy! I'll report back on my progress

Edit 4: Too many edits. In case any one is wondering, you can get the char name by using GetUnitName("player")

edit 5: WOOOOT got it to work. sort of! I can count killing blows (but not straight of kills)

in case anyone is wondering, my code looks like

Code:
function OnKill( eventCode , result , isError , abilityName, abilityGraphic, abilityActionSlotType, sourceName, sourceType, targetName, targetType, hitValue, powerType, damageType, log )
	--d(sourceName)
	--d("Unit Name: " .. (GetUnitName("player") .. "^Fx"))

	if result == ACTION_RESULT_KILLING_BLOW and sourceName == (GetUnitName("player") .. "^Fx") then
		--d("Works")
		counter = counter + 1
	end
end

Last edited by mikethecoder4 : 04/21/14 at 02:41 PM.
 

ESOUI » Developer Discussions » General Authoring Discussion » Detecting Deaths


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