1. Hello,

    I do not use " if(hitinfo.Initiator:ToPlayer()) then" without making mistakes.
    Code :
    Code:
    function PLUGIN:OnEntityDeath(entity, hitinfo)
        if(entity:GetComponent("BaseNPC")) then
            if(hitinfo.Initiator:ToPlayer()) then
                player = hitinfo.Initiator:ToPlayer()
                userdata = API:GetUserDataFromPlayer(player)
                animal = entity:LookupShortPrefabName()
                if animal == "bear.prefab" and Settings.Enabled.Bear == "true" then
                    userdata:Deposit(tonumber(Settings.Amount.Bear))
                    if Settings.Enabled.Messages == "true" then
                        rust.SendChatMessage(player, BuildOutput(Settings.Messages.Kill, {"{prefix}", "{amount}", "{entity}"}, {Settings.Messages.Prefix, Settings.Amount.Bear, Settings.Name.Bear}))
                    end
                elseif
    Error :
    Code:
    6:23 PM [Error] Failed to call hook 'OnEntityDeath' on plugin 'testhunt v0.0.3'
    File: testhunt.lua Line: 56 attempt to index field 'Initiator' (a nil value):
      at NLua.Lua.ThrowExceptionFromError (Int32 oldTop) [0x00000] in <filename unknown>:0
      at NLua.Lua.CallFunction (System.Object function, System.Object[] args, System.Type[] returnTypes) [0x00000] in <filename unknown>:0
      at NLua.Lua.CallFunction (System.Object function, System.Object[] args) [0x00000] in <filename unknown>:0
      at NLua.LuaFunction.Call (System.Object[] args) [0x00000] in <filename unknown>:0
      at Oxide.Ext.Lua.Plugins.LuaPlugin.OnCallHook (System.String hookname, System.Object[] args) [0x00000] in <filename unknown>:0
      at Oxide.Core.Plugins.Plugin.CallHook (System.String hookname, System.Object[] args) [0x00000] in <filename unknown>:0 
    Line: 56 => if(hitinfo.Initiator:ToPlayer()) then

    Would know how to use her without creating error?
     
  2. Wulf

    Wulf Community Admin

    The Initiator would be who killed the player, which may not always exist. You should be doing a nil/null check on it before trying to convert to a player.

    If you are wanting to see who actually died, you'd want entity:ToPlayer().
     
  3. Code:
    if hitinfo.Initiator:ToPlayer() ~= nil then
    ?
     
  4. Wulf

    Wulf Community Admin

    Remove :ToPlayer()

    if not hitInfo.Initiator then return end
     
  5. No error , but it no longer works x)
    Code:
    function PLUGIN:OnEntityDeath(entity, hitinfo)
        if(entity:GetComponent("BaseNPC")) then
            if not hitInfo.Initiator then return end
            player = hitinfo.Initiator:ToPlayer()
            userdata = API:GetUserDataFromPlayer(player)
            animal = entity:LookupShortPrefabName()
            print("Joueur : "..player.." Data : "..userdata.." Animal : "..animal)
     
  6. Wulf

    Wulf Community Admin

    As I mentioned previously, the initiator is what attacked/killed the player. The entity would be the player.
     
  7. Sorry, not well understood.
    My goal is to know who killed animal.

    1- if(entity:GetComponent("BaseNPC")) then => I verifi it's an animal.
    2- if(hitinfo.Initiator:ToPlayer()) then => I verifi that this is a player who killed the animal.

    then

    player = hitinfo.Initiator:ToPlayer() => player = player who killed the animal.
    [DOUBLEPOST=1445880786,1445802568][/DOUBLEPOST]Nobody knows why this makes mistakes and how to avoid it?
     
  8. Wulf

    Wulf Community Admin

    Your hitInfo (hitinfo) casing doesn't match.