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 |
Quote:
Lua Code:
And make filter for OnInitialized function. You don't want to trigger this event each time any addon loads, don't you? Lua Code:
Or you initialised your addon from XML file (self parameter makes me think like that) and I'm wrong :D 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:
|
Quote:
|
Quote:
|
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.
|
Quote:
|
Quote:
Quote:
|
Quote:
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. |
Quote:
Quote:
Quote:
Quote:
Quote:
|
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. |
Quote:
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? |
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 ) Code:
EVENT_MANAGER:RegisterForEvent("KillCounter", EVENT_PLAYER_DEAD, OnKilled) 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. |
Check the source name against your name.
|
Quote:
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 ) |
Lua Code:
GetDisplayName() returns the name of the account, not the name of the player. |
Quote:
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? |
Quote:
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. Quote:
|
Quote:
Thanks alot, this thread has been very informative for me |
Quote:
|
Quote:
Code:
GetUnitName("player") == zo_strformat("<<1>>", sourceName) |
All times are GMT -6. The time now is 09:51 PM. |
vBulletin © 2024, Jelsoft Enterprises Ltd
© 2014 - 2022 MMOUI