From 5f3d1c8adc4e10bd3844e87312e36e9b77249927 Mon Sep 17 00:00:00 2001 From: Luke Policinski Date: Mon, 2 Nov 2026 22:51:39 -0500 Subject: [PATCH] bug: damage from an M4A1-S, USP-S, CZ75, R8 or MP5-SD is stored under that gun player_hurt names the entity class, which CS2 shares with the base gun (the M4A1-S is a weapon_m4a1), so the damage landed on the M4A4, P2000, P250, Deagle or MP7 while kills kept the right name. The damage event now names the gun in hand through CommunityWeapons.InHand, the same lookup player-management already uses for hurt events. --- .../src/FiveStack.Events/PlayerDamage.cs | 19 ++++++++++++++++++- .../src/FiveStack.Events/PlayerDamage.cs | 19 ++++++++++++++++++- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/apps/counterstrikesharp/src/FiveStack.Events/PlayerDamage.cs b/apps/counterstrikesharp/src/FiveStack.Events/PlayerDamage.cs index 71c0e273..14737852 100644 --- a/apps/counterstrikesharp/src/FiveStack.Events/PlayerDamage.cs +++ b/apps/counterstrikesharp/src/FiveStack.Events/PlayerDamage.cs @@ -67,7 +67,12 @@ public HookResult OnPlayerDamage(EventPlayerHurt @event, GameEventInfo info) ? $"{Convert.ToInt32(attackerLocation.X)} {Convert.ToInt32(attackerLocation.Y)} {Convert.ToInt32(attackerLocation.Z)}" : "" }, - { "weapon", $"{(@event.Weapon.Length == 0 ? "worldent" : @event.Weapon)}" }, + { + "weapon", + @event.Weapon.Length == 0 + ? "worldent" + : CommunityWeapons.InHand(@event.Weapon, ActiveItemDefinitionIndex(attacker)) + }, { "damage", damageDealt }, { "damage_armor", @event.DmgArmor }, { "hitgroup", $"{DamageUtility.HitGroupToString(@event.Hitgroup)}" }, @@ -87,4 +92,16 @@ public HookResult OnPlayerDamage(EventPlayerHurt @event, GameEventInfo info) return HookResult.Continue; } + + private static int? ActiveItemDefinitionIndex(CCSPlayerController? player) + { + CBasePlayerWeapon? weapon = player?.PlayerPawn.Value?.WeaponServices?.ActiveWeapon.Value; + + if (weapon == null || !weapon.IsValid) + { + return null; + } + + return weapon.AttributeManager.Item.ItemDefinitionIndex; + } } diff --git a/apps/swiftly/src/FiveStack.Events/PlayerDamage.cs b/apps/swiftly/src/FiveStack.Events/PlayerDamage.cs index 5b0ebd49..2eb2e0f0 100644 --- a/apps/swiftly/src/FiveStack.Events/PlayerDamage.cs +++ b/apps/swiftly/src/FiveStack.Events/PlayerDamage.cs @@ -76,7 +76,12 @@ public HookResult OnPlayerDamage(EventPlayerHurt @event) ? $"{Convert.ToInt32(attackerLocation.Value.X)} {Convert.ToInt32(attackerLocation.Value.Y)} {Convert.ToInt32(attackerLocation.Value.Z)}" : "" }, - { "weapon", @event.Weapon.Length == 0 ? "worldent" : @event.Weapon }, + { + "weapon", + @event.Weapon.Length == 0 + ? "worldent" + : CommunityWeapons.InHand(@event.Weapon, ActiveItemDefinitionIndex(attackerPawn)) + }, { "damage", damageDealt }, { "damage_armor", @event.DmgArmor }, { "hitgroup", DamageUtility.HitGroupToString((int)@event.ActualHitGroup) }, @@ -97,4 +102,16 @@ public HookResult OnPlayerDamage(EventPlayerHurt @event) return HookResult.Continue; } #pragma warning restore CS0618 + + private static int? ActiveItemDefinitionIndex(CCSPlayerPawn? pawn) + { + CBasePlayerWeapon? weapon = pawn?.WeaponServices?.ActiveWeapon.Value; + + if (weapon == null || !weapon.IsValid) + { + return null; + } + + return weapon.AttributeManager.Item.ItemDefinitionIndex; + } }