Skip to content

Commit

Permalink
fix: Statistics line print even if no damages to show
Browse files Browse the repository at this point in the history
  • Loading branch information
K4ryuu committed Jan 29, 2024
1 parent 624c688 commit 73a481e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
-- 2024.01.26 - V2.0.3

- fix: Crash if you shoot bot with console enabled
- fix: Statistics line print even if no damages to show

-- 2024.01.26 - V2.0.2

- feat: Option to set global damage stats (for mm or small servers) to see everyone's given and taken damages
Expand Down
32 changes: 24 additions & 8 deletions src/K4ryuuDamageInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using CounterStrikeSharp.API;
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Core.Attributes;
using CounterStrikeSharp.API.Modules.Utils;
using Microsoft.Extensions.Logging;

namespace K4ryuuDamageInfo
Expand All @@ -19,6 +18,9 @@ public sealed class PluginConfig : BasePluginConfig
[JsonPropertyName("round-end-summary-show-all-damages")]
public bool ShowAllDamages { get; set; } = false;

[JsonPropertyName("round-end-summary-show-all-damages-enemies-only")]
public bool ShowAllDamagesTeamOnly { get; set; } = true;

[JsonPropertyName("center-damage-info")]
public bool CenterDamageInfo { get; set; } = true;

Expand All @@ -36,7 +38,7 @@ public sealed class PluginConfig : BasePluginConfig
public class DamageInfoPlugin : BasePlugin, IPluginConfig<PluginConfig>
{
public override string ModuleName => "Damage Info";
public override string ModuleVersion => "2.0.2";
public override string ModuleVersion => "2.0.3";
public override string ModuleAuthor => "K4ryuu";

public required PluginConfig Config { get; set; } = new PluginConfig();
Expand Down Expand Up @@ -125,7 +127,9 @@ private HookResult OnPlayerHurt(EventPlayerHurt @event, GameEventInfo info)
if (Config.ConsoleDamageInfo)
{
attacker.PrintToConsole(Localizer["phrases.console.normal", victim.PlayerName, damageToHeath, damageToArmor, hitgroup]);
victim.PrintToConsole(Localizer["phrases.console.inverse", attacker.PlayerName, damageToHeath, damageToArmor, hitgroup]);

if (!victim.IsBot)
victim.PrintToConsole(Localizer["phrases.console.inverse", attacker.PlayerName, damageToHeath, damageToArmor, hitgroup]);
}

if (Config.CenterDamageInfo)
Expand Down Expand Up @@ -222,13 +226,16 @@ private void DisplayDamageInfo(CCSPlayerController player)
if (IsDataShown.ContainsKey(player.Slot) && IsDataShown[player.Slot])
return;

IsDataShown[player.Slot] = true;
player.PrintToChat($" {Localizer["phrases.summary.startline"]}");

if (Config.ShowAllDamages)
{
Dictionary<int, (DamageInfo given, DamageInfo taken)>? allPlayerSummaries = new Dictionary<int, (DamageInfo given, DamageInfo taken)>();

if (allPlayerSummaries.Count == 0)
return;

IsDataShown[player.Slot] = true;
player.PrintToChat($" {Localizer["phrases.summary.startline"]}");

foreach (var playerDamage in playerDamageInfos)
{
allPlayerSummaries[playerDamage.Key] = SummarizePlayerDamage(playerDamage.Value);
Expand All @@ -237,6 +244,10 @@ private void DisplayDamageInfo(CCSPlayerController player)
foreach (var summary in allPlayerSummaries)
{
CCSPlayerController otherPlayer = Utilities.GetPlayerFromSlot(summary.Key);

if (Config.ShowAllDamagesTeamOnly && otherPlayer.TeamNum == player.TeamNum)
continue;

string otherPlayerHealth = otherPlayer.PlayerPawn.Value!.Health > 0
? $"{otherPlayer.PlayerPawn.Value!.Health}HP"
: $"{Localizer["phrases.dead"]}";
Expand All @@ -246,16 +257,21 @@ private void DisplayDamageInfo(CCSPlayerController player)
summary.Value.taken.TotalDamage, summary.Value.taken.Hits,
otherPlayer.PlayerName, otherPlayerHealth]}");
}

player.PrintToChat($" {Localizer["phrases.summary.endline"]}");
}
else
{
if (!playerDamageInfos.ContainsKey(player.Slot))
return;

IsDataShown[player.Slot] = true;
player.PrintToChat($" {Localizer["phrases.summary.startline"]}");

DisplayPlayerDamageInfo(player, playerDamageInfos[player.Slot]);
}

player.PrintToChat($" {Localizer["phrases.summary.endline"]}");
player.PrintToChat($" {Localizer["phrases.summary.endline"]}");
}
}

private (DamageInfo given, DamageInfo taken) SummarizePlayerDamage(PlayerDamageInfo playerInfo)
Expand Down

0 comments on commit 73a481e

Please sign in to comment.