From f81633711fd3e3811fcca515ef77e8742df6f62a Mon Sep 17 00:00:00 2001 From: K4ryuu <104531589+K4ryuu@users.noreply.github.com> Date: Sat, 30 Mar 2024 20:45:28 +0100 Subject: [PATCH] fix: Schema target points to null --- CHANGELOG | 4 ++++ src/K4ryuuDamageInfo.cs | 40 ++++++++++++++++++++++++++++++++-------- 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 1663d1f..5fa613f 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,7 @@ +-- 2024.03.30 - V2.3.2 + +fix: Schema target points to null + -- 2024.03.26 - V2.3.1 - fix: Start/End line problems diff --git a/src/K4ryuuDamageInfo.cs b/src/K4ryuuDamageInfo.cs index c1e761c..228dc00 100644 --- a/src/K4ryuuDamageInfo.cs +++ b/src/K4ryuuDamageInfo.cs @@ -57,7 +57,7 @@ public sealed class PluginConfig : BasePluginConfig public class DamageInfoPlugin : BasePlugin, IPluginConfig { public override string ModuleName => "Damage Info"; - public override string ModuleVersion => "2.3.1"; + public override string ModuleVersion => "2.3.2"; public override string ModuleAuthor => "K4ryuu"; public required PluginConfig Config { get; set; } = new PluginConfig(); @@ -292,14 +292,23 @@ private void DisplayDamageInfo(CCSPlayerController player) if (Config.ShowAllDamagesTeamOnly && otherPlayer.TeamNum == player.TeamNum) continue; - string otherPlayerHealth = otherPlayer.PlayerPawn.Value!.Health > 0 - ? $"{otherPlayer.PlayerPawn.Value!.Health}HP" + int otherPlayerHealth = 0; + string otherPlayerName = "Unknown"; + + if (otherPlayer?.IsValid == true) + { + otherPlayerName = otherPlayer.PlayerName; + otherPlayerHealth = otherPlayer.PlayerPawn?.IsValid == true && otherPlayer.Connected == PlayerConnectedState.PlayerConnected ? otherPlayer.PlayerPawn.Value?.Health ?? 0 : 0; + } + + string otherPlayerHealthString = otherPlayerHealth > 0 + ? $"{otherPlayerHealth}HP" : $"{Localizer["phrases.dead"]}"; player.PrintToChat($" {Localizer["phrases.summary.dataline", summary.Value.taken.TotalDamage, summary.Value.taken.Hits, summary.Value.given.TotalDamage, summary.Value.given.Hits, - otherPlayer.PlayerName, otherPlayerHealth]}"); + otherPlayerName, otherPlayerHealthString]}"); } player.PrintToChat($" {Localizer["phrases.summary.endline"]}"); @@ -355,10 +364,18 @@ private void DisplayPlayerDamageInfo(CCSPlayerController player, PlayerDamageInf DamageInfo takenDamageInfo = playerInfo.TakenDamage.ContainsKey(otherPlayerId) ? playerInfo.TakenDamage[otherPlayerId] : new DamageInfo(); processedPlayers.Add(otherPlayerId); + int otherPlayerHealth = 0; + string otherPlayerName = "Unknown"; + CCSPlayerController otherPlayer = Utilities.GetPlayerFromSlot(otherPlayerId); - int otherPlayerHealth = otherPlayer.PlayerPawn.Value!.Health; - player.PrintToChat($" {Localizer["phrases.summary.dataline", givenDamageInfo.TotalDamage, givenDamageInfo.Hits, takenDamageInfo.TotalDamage, takenDamageInfo.Hits, otherPlayer.PlayerName, otherPlayerHealth > 0 ? $"{otherPlayerHealth}HP" : $"{Localizer["phrases.dead"]}"]}"); + if (otherPlayer?.IsValid == true) + { + otherPlayerName = otherPlayer.PlayerName; + otherPlayerHealth = otherPlayer.PlayerPawn?.IsValid == true && otherPlayer.Connected == PlayerConnectedState.PlayerConnected ? otherPlayer.PlayerPawn.Value?.Health ?? 0 : 0; + } + + player.PrintToChat($" {Localizer["phrases.summary.dataline", givenDamageInfo.TotalDamage, givenDamageInfo.Hits, takenDamageInfo.TotalDamage, takenDamageInfo.Hits, otherPlayerName, otherPlayerHealth > 0 ? $"{otherPlayerHealth}HP" : $"{Localizer["phrases.dead"]}"]}"); } foreach (KeyValuePair entry in playerInfo.TakenDamage) @@ -379,11 +396,18 @@ private void DisplayPlayerDamageInfo(CCSPlayerController player, PlayerDamageInf DamageInfo takenDamageInfo = entry.Value; DamageInfo givenDamageInfo = new DamageInfo(); + int otherPlayerHealth = 0; + string otherPlayerName = "Unknown"; + CCSPlayerController otherPlayer = Utilities.GetPlayerFromSlot(otherPlayerId); - int otherPlayerHealth = otherPlayer.PlayerPawn.Value!.Health; + if (otherPlayer?.IsValid == true) + { + otherPlayerName = otherPlayer.PlayerName; + otherPlayerHealth = otherPlayer.PlayerPawn?.IsValid == true && otherPlayer.Connected == PlayerConnectedState.PlayerConnected ? otherPlayer.PlayerPawn.Value?.Health ?? 0 : 0; + } - player.PrintToChat($" {Localizer["phrases.summary.dataline", givenDamageInfo.TotalDamage, givenDamageInfo.Hits, takenDamageInfo.TotalDamage, takenDamageInfo.Hits, otherPlayer.PlayerName, otherPlayerHealth > 0 ? $"{otherPlayerHealth}HP" : $"{Localizer["phrases.dead"]}"]}"); + player.PrintToChat($" {Localizer["phrases.summary.dataline", givenDamageInfo.TotalDamage, givenDamageInfo.Hits, takenDamageInfo.TotalDamage, takenDamageInfo.Hits, otherPlayerName, otherPlayerHealth > 0 ? $"{otherPlayerHealth}HP" : $"{Localizer["phrases.dead"]}"]}"); } if (printed)