So this code should work. but for some reason it does not lower his humanity upon killing a player.
Rank: 0 - NeutralCode:void OnEntityDeath(BaseCombatEntity entity, HitInfo info) { try { if(entity != null) { BasePlayer attacker; BasePlayer victim; if (!info?.Initiator is BasePlayer) return; if(!entity is BasePlayer) return; attacker = info?.Initiator?.ToPlayer(); victim = entity.ToPlayer(); if(!humanityData.playerH.ContainsKey(attacker.userID)) OnPlayerInit(attacker); if(!humanityData.playerH.ContainsKey(victim.userID)) OnPlayerInit(victim); if(humanityData.playerH[victim.userID].Rank == 0 || humanityData.playerH[victim.userID].Rank == 1) { humanityData.playerH[attacker.userID].Humanity = humanityData.playerH[attacker.userID].Humanity - Convert.ToInt32(Config["HumanityLossGainOnKill"]); CheckStats(attacker); SaveData(); return; } if(humanityData.playerH[victim.userID].Rank == 2) { humanityData.playerH[attacker.userID].Humanity = humanityData.playerH[attacker.userID].Humanity + Convert.ToInt32(Config["HumanityLossGainOnKill"]); CheckStats(attacker); SaveData(); return; } } } catch(System.Exception) {return;} }
Rank: 1 - Hero
Rank: 2 - Bandit
Data:
For some reason when a player kills a bandit it does not lower his humanity. And im not sure about gaining humanity(killing a bandit).Code:class HumanityData { public Dictionary<ulong, players> playerH = new Dictionary<ulong, players>(); public HumanityData(){} } class players { public string playerName; public ulong playerID; public int Humanity; public int Rank; public players(){} }
Humanity not lowering as it should
Discussion in 'Rust Development' started by DylanSMR, Jul 9, 2016.
-
I am not really sure what could be wrong but I cleaned your code a little bit (in my opinion this is cleaner)
I might have gotten you way to decrease / increase humanity wrong though.
I thought you wanna give + humanity for killing bandits and - humanity for killing innocent people or heroes.
Code:static HumanityData humanityData = new HumanityData(); class HumanityData { public Dictionary<ulong, players> playerH = new Dictionary<ulong, players>(); public HumanityData() { } } class players { public string playerName; public ulong playerID; public int Humanity; public int Rank; public players() { } internal static players Find(BasePlayer player) { return humanityData.playerH.Values.First((d) => d.playerID == player.userID); } } void OnEntityDeath(BaseCombatEntity victimEntity, HitInfo info) { if (info?.Initiator?.ToPlayer() != null && victimEntity?.ToPlayer() != null) { BasePlayer victim = victimEntity.ToPlayer(); BasePlayer attacker = info.Initiator.ToPlayer(); if (players.Find(victim) == null) OnPlayerInit(victim); if (players.Find(attacker) == null) OnPlayerInit(attacker); players victimData = players.Find(victim); players attackerData = players.Find(victim); if (victimData.Rank == 0 || victimData.Rank == 1) { attackerData.Humanity -= Convert.ToInt32(Config["HumanityLossGainOnKill"]); CheckStats(attacker); SaveData(); } else if (victimData.Rank == 2) { attackerData.Humanity += Convert.ToInt32(Config["HumanityLossGainOnKill"]); CheckStats(attacker); SaveData(); } } } void OnPlayerInit(BasePlayer player) { // Do your stuff } -
I will try that. Thanks for the response!
[DOUBLEPOST=1468102961][/DOUBLEPOST]Hey so do you have any idea how I would fix the problem where people can see names through walls with this code? I have a idea but I think it would cause some server lag.
Code:void CheckDis() { try { foreach(var player in BasePlayer.activePlayerList) { BasePlayer nearbyP = null; List<BaseEntity> nearby = new List<BaseEntity>(); Vis.Entities(player.transform.position, 20, nearby); foreach (var ent in nearby) if (ent is BasePlayer) nearbyP = ent.ToPlayer(); DrawChatMessage(player, nearbyP); } timer.Once(1, () => CheckDis()); } catch(System.Exception) { return; } } void DrawChatMessage (BasePlayer player, BasePlayer nearby) { try { var rankname = ""; if(humanityData.playerH[player.userID].Rank == 0) { rankname = "Neutral"; } else if(humanityData.playerH[player.userID].Rank == 1) { rankname = "Hero"; } else if(humanityData.playerH[player.userID].Rank == 2) { rankname = "Bandit"; } else { OnPlayerInit(player); return; } var ranknamex = "[test]"; var lastMessage = ranknamex.Replace("test", rankname); Color messageColor = new Color(1,1,1,1); nearby.SendConsoleCommand("ddraw.text", 0.1f, messageColor, player.transform.position + new Vector3(0, 1.9f, 0),"<size=25>" + lastMessage + "</size>"); timer.Repeat(0.1f, 1, () => { nearby.SendConsoleCommand("ddraw.text", 0.1f, messageColor, player.transform.position + new Vector3(0, 1.9f, 0),"<size=25>" + lastMessage + "</size>"); }); } catch(System.Exception) { return; } } -
I was thinking of a players eye sight but idk yet
-
I am not sure right now but somewhere in BaseEntity or BasePlayer there is something like IsVisible()
You should try that. -
Yup I will when I get home. Starting the drive home tomorrow
