1. Hey,
    i need a example of an "check" or "if" (sorry i dont know the exact words in english)
    if someone killed a NPC or a Player.

    And "realized" if i use the hook
    Code:
    object OnPlayerDie(BasePlayer player, HitInfo info)
    Its called if a Scientist die or ist killed by a player.

    I need a "call" if a player kills a Scientist.
    And a "call" if ONLY a Player Dies (no Scientist or other NPC's)
     
  2. Check info's initiator for Baseplayer class. And then if initiator isnt a npc (IsNpc) - do action
     
  3. Scientists, Murderers, Bandits and real players are all BasePlayer,
    but Scientists, Murderers and Bandits are NPCPlayer (type of BasePlayer),
    so this should do it.

    Code:
    if (player is BasePlayer )
    {
        if (player is NPCPlayer)
        {
            //do stuff to NPCPlayer
        }
        else
        {
           //must be a real player
        }
    }
    You can also check for NPCMurderer/Scientist specifically.
     
    Last edited by a moderator: Aug 28, 2018
  4. Thank you Very Very much :)

    a quick question is there a way to check if a player is in a group and if not add the player to group :)
     
  5. Code:
    if (!permission.UserHasGroup(player.UserIDString, "groupname"))
    {
        permission.AddUserGroup(player.UserIDString, "groupname");
    }
     
  6. Thanks again :)
    Last Question. How to check a killer and the hostile?
    I mean how to check if a player kill a player, a player kill a npc, or a npc a player?

    My Example:
    Code:
            void OnEntityDeath(BaseCombatEntity victimEntity, HitInfo info)
            {
                if (info?.Initiator?.ToPlayer() != null && victimEntity?.ToPlayer() != null)
                {
                    BasePlayer victim = victimEntity.ToPlayer();
                    BasePlayer attacker = info.Initiator.ToPlayer();
                    CuiHelper.DestroyUi(victim, "HumanUI");
                    if(victim.userID == attacker.userID) return;
    
                    if (players.Find(victim) == null)
                        OnPlayerInit(victim);
    
                    if (players.Find(attacker) == null)
                        OnPlayerInit(attacker);
    
                    players victimData = players.Find(victim);
                    players attackerData = players.Find(attacker);
    
                    victimData.Deaths++;
                    attackerData.Kills++;
    
                    if (victimData.Rank == 0 || victimData.Rank == 1)
                    {
                        attackerData.Humanity -= Convert.ToInt32(Config["HumanityLossGainOnKill"]);
                        RankAlgorithm(attacker);
                    }
                    else if (victimData.Rank == 2)
                    {
                        attackerData.Humanity += Convert.ToInt32(Config["HumanityLossGainOnKill"]);
                        RankAlgorithm(attacker);
                    }
                    SaveData();
                }
            }
    If i kill a NPC i get decreased Humanity.. and another problem is that the NPC's with the ID's registered in the data file.. Sorry my english is not the best i hope you know what i mean. with my bad english it is a pain to look for solutions. I hope you understand what I mean and you can help me.
     
    Last edited by a moderator: Aug 29, 2018
  7. My reply above doesn't detail every possibility, but if gives you the tools you need.

    You'd want to run your !(* is NPCPlayer) checks before you run things like players.Find and OnPlayerInit.

    Code:
    if (player != null && !(player is NPCPlayer))
    {
    //code only runs for real players.
    }