1. How would i detect if its a player if not return?

    Code:
            void OnKillNPC(BasePlayer npc, HitInfo hinfo)
            {
               if (!npcData.NpcTP.ContainsKey(npc.UserIDString)) return; // Check if this NPC is registered
                if (hinfo == null) return;
                var player = hinfo.Initiator.ToPlayer();
                ulong playerId = player.userID;
                string npcId = npc.UserIDString;
                var EnableDead = npcData.NpcTP[npcId].EnableDead;
                var DeadOnPlayer = npcData.NpcTP[npcId].DeadOnPlayer;
                string DeadCmd = npcData.NpcTP[npcId].DeadCmd;
                string DeadArgs = npcData.NpcTP[npcId].DeadArgs;
                var bad = "somthing is not right somewhere in DeadCmd";
                  if (EnableDead)
                    if (!DeadOnPlayer) // Check if this is command on player
                    {
                        rust.RunServerCommand($"{DeadCmd} {DeadArgs}");                 }
                    if (DeadOnPlayer) // Check if this is command on player
                    {
                        rust.RunServerCommand($"{DeadCmd} {playerId} {DeadArgs}");                 }
                    else PrintError((string)bad); // Otherwise print the error message to console so server owners know there is a problem            }
     
  2. Wulf

    Wulf Community Admin

    Where is the OnKillNPC hook coming from?

    You can get the player from Rust's HitInfo like this:
    Code:
    var attacker = info.Initiator as BasePlayer;
    There are other methods too, like (BasePlayer)info.Initiator or info.Initiator.ToPlayer() maybe.
     
  3. the hook is from Human Npc
    [DOUBLEPOST=1486069203][/DOUBLEPOST]thanks that worked.