Skip to content

Commit

Permalink
fix: Schema target points to null
Browse files Browse the repository at this point in the history
  • Loading branch information
K4ryuu committed Mar 30, 2024
1 parent 733d587 commit f816337
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 8 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -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
Expand Down
40 changes: 32 additions & 8 deletions src/K4ryuuDamageInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public sealed class PluginConfig : BasePluginConfig
public class DamageInfoPlugin : BasePlugin, IPluginConfig<PluginConfig>
{
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();
Expand Down Expand Up @@ -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"]}");
Expand Down Expand Up @@ -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<int, DamageInfo> entry in playerInfo.TakenDamage)
Expand All @@ -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)
Expand Down

0 comments on commit f816337

Please sign in to comment.