Originally Posted by mikethecoder4
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:
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:
function OnInitialized(eventCode, addOnName)
If addOnName~="KillCounter" then return end
...
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:
function OnKill(unitTag, isDead)
If unitTag==GetUnitName("player") and isDead then
...
end
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.