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, 09:10 AM   #7
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.
Originally Posted by Iyanga View Post
Or maybe the wiki is wrong and you just don't want to accept it.
I think they both right. Looks like it's just an analog of 'self', adapted for events.
 
04/21/14, 09:28 AM   #8
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Feb 2014
Posts: 648
Originally Posted by Iyanga View Post
Or maybe the wiki is wrong and you just don't want to accept it.
/facepalm Really? You're going to bring your stubbornness to this thread, too? Should I ask you to reread the explanation I wrote up again? Just because some people make mistakes when learning a new API does not make that API documentation wrong. It just means that they have to read up on how to use it better. Saying it's wrong because you didn't get it the first time is akin to blaming your gutter ball in bowling on the lane not being level. Just accept the API as it's supposed to be, learn a little, grow a little, stop blaming others, and start helping others understand how things work.

You DO realize the the API was provided by ZOS, right? So you know their API better than them?


@OP: I apologize for Iyanga bringing this negativity into your thread.
 
04/21/14, 10:56 AM   #9
Iyanga
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 183
Originally Posted by Seerah View Post
/facepalm Really? You're going to bring your stubbornness to this thread, too?
You insisted that Garkin is wrong and brought the topic whether the wiki is right or not here. That wasn't me. Obviously you had the urge to defend the Wiki here.

Should I ask you to reread the explanation I wrote up again?
Should I ask you to reread the explanation I wrote up again?

and start helping others understand how things work.
I never blamed anyone for anything. You are blaming people for not understanding the Wiki properly. So instead of fixing the Wiki it's better to explain them over and over here in the forum that they are using the Wiki in the wrong way. Well, if this makes sense to you......


You DO realize the the API was provided by ZOS, right? So you know their API better than them?
You don't really call this API documentation, what ZOS provided, do you?


@OP: I apologize for Iyanga bringing this negativity into your thread.
Somehow you are the only one who is negative here.
 
04/21/14, 11:45 AM   #10
Iyanga
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 183
By the way, that you don't agree that the Wiki needs to have the function signatures for the callback functions documented and not the event signature, does not mean that you are allowed to attack me as a person.

I would prefer if you would refrain from personal attacks in the future.
 
04/21/14, 11:47 AM   #11
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   #12
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   #13
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   #14
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.
 
04/21/14, 02:11 PM   #15
Iyanga
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 183
Lua Code:
  1. if sourceType == COMBAT_UNIT_TYPE_PLAYER and GetUnitName("player") == zo_strformat("<<1>>", sourceName) then
  2.     -- increase counter
  3.   else
  4.     -- Discard - not for us
  5.   end


GetDisplayName() returns the name of the account, not the name of the player.

Last edited by Iyanga : 04/21/14 at 02:17 PM.
 
04/21/14, 02:45 PM   #16
mikethecoder4
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 13
Originally Posted by Iyanga View Post
Lua Code:
  1. if sourceType == COMBAT_UNIT_TYPE_PLAYER and GetUnitName("player") == zo_strformat("<<1>>", sourceName) then
  2.     -- increase counter
  3.   else
  4.     -- Discard - not for us
  5.   end


GetDisplayName() returns the name of the account, not the name of the player.

Hmm this is intersting. What is sourceType exactly? thought it was the damage type.

However, wouldn't this code increase the counter every time I did damage?
 
04/21/14, 02:55 PM   #17
Iyanga
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 183
Originally Posted by mikethecoder4 View Post
Hmm this is intersting. What is sourceType exactly? thought it was the damage type.

However, wouldn't this code increase the counter every time I did damage?
No, damage type is damageType
sourceType is of CombatUnitType, as is targetType.

You need to check sourceType and sourceName, because you can't prevent people naming themselves Scamp or Wolf.

However, wouldn't this code increase the counter every time I did damage?
You still need to filter out all action results you don't care about, too, of course. My snippet is just to verify that it is the player whose event you process.
 
04/21/14, 02:58 PM   #18
mikethecoder4
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 13
Originally Posted by Iyanga View Post
No, damage type is damageType
sourceType is of CombatUnitType, as is targetType.

You need to check sourceType and sourceName, because you can't prevent people naming themselves Scamp or Wolf.



You still need to filter out all action results you don't care about, too, of course. My snippet is just to verify that it is the player whose event you process.
Ahh very interesting. This helps immensely thank you! I didnt think about checking the source type.

Thanks alot, this thread has been very informative for me
 
04/21/14, 02:58 PM   #19
Iyanga
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 183
Originally Posted by mikethecoder4 View Post
Lua Code:
  1. GetUnitName("player") .. "^Fx"
This will break for male player characters.
 
04/21/14, 03:46 PM   #20
mikethecoder4
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 13
Originally Posted by Iyanga View Post
This will break for male player characters.
I changed that to
Code:
GetUnitName("player") == zo_strformat("<<1>>", sourceName)
as per your suggestion. I was wondering what the Fx and Mx stood for.
 

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