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
Its called if a Scientist die or ist killed by a player.Code:object OnPlayerDie(BasePlayer player, HitInfo info)
I need a "call" if a player kills a Scientist.
And a "call" if ONLY a Player Dies (no Scientist or other NPC's)
Check if someone killed a NPC or Player
Discussion in 'Rust Development' started by BattleSheep, Aug 28, 2018.
-
Check info's initiator for Baseplayer class. And then if initiator isnt a npc (IsNpc) - do action
-
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 } }
Last edited by a moderator: Aug 28, 2018 -
a quick question is there a way to check if a player is in a group and if not add the player to group -
Code:
if (!permission.UserHasGroup(player.UserIDString, "groupname")) { permission.AddUserGroup(player.UserIDString, "groupname"); }
-
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(); } }
Last edited by a moderator: Aug 29, 2018 -
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. }