From 3f3d394fe7155d4091704aba325923507068ef77 Mon Sep 17 00:00:00 2001 From: node2024 <146072189+node2024@users.noreply.github.com> Date: Wed, 15 Nov 2023 13:37:22 +0900 Subject: [PATCH] Give health on Kill Enemy Ensure that health is restored when an enemy is killed. Also, toggle the "give health shot" option when updating the HUD to keep the HUD updated. This would allow the HUD to be updated in a way that does not detract from the player's experience. HUD Updated tech by K4ryuu https://discord.com/channels/1160907911501991946/1160907912445710482/1173076426753331283 --- DeathmatchPlugin/DeathmatchPlugin.cs | 1 + .../Effects/RefillPlayerHealth.cs | 33 +++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 DeathmatchPlugin/Effects/RefillPlayerHealth.cs diff --git a/DeathmatchPlugin/DeathmatchPlugin.cs b/DeathmatchPlugin/DeathmatchPlugin.cs index 8a51f59..103e8b5 100644 --- a/DeathmatchPlugin/DeathmatchPlugin.cs +++ b/DeathmatchPlugin/DeathmatchPlugin.cs @@ -135,6 +135,7 @@ public HookResult OnPlayerDeath(EventPlayerDeath @event, GameEventInfo info) _killstreakManager.OnKill(attacker); RefillPlayerAmmo.Do(attacker); + RefillPlayerHealth.onKill(attacker); return HookResult.Continue; } diff --git a/DeathmatchPlugin/Effects/RefillPlayerHealth.cs b/DeathmatchPlugin/Effects/RefillPlayerHealth.cs new file mode 100644 index 0000000..c4f7629 --- /dev/null +++ b/DeathmatchPlugin/Effects/RefillPlayerHealth.cs @@ -0,0 +1,33 @@ +using CounterStrikeSharp.API.Core; +using CounterStrikeSharp.API.Modules.Memory; +using DeathmatchPlugin.Config; +using DeathmatchPlugin.Utilities; +namespace DeathmatchPlugin.Effects; + +public static class RefillPlayerHealth { + + public static void onKill(CCSPlayerController player) + { + if (player.Health == 100) return; + string giveBack = "weapon_healthshot"; + string playerName = player.PlayerName; + player.PlayerPawn.Value.Health = 100; // give health + player.PlayerPawn.Value.MaxHealth = 100; + player.PlayerPawn.Value.ArmorValue = 100; // give armor + // PrintChat giveHealth + player.PrintToChat($"{DeathmatchConfig.ChatPrefix} {Colored.Blue(playerName)} : {Colored.Green("+100")} hp"); + /* + Due to the nature of the HUD, the HUD is not updated until an action is taken by an external factor, + so the HUD is updated using healthShot. + */ + foreach (var weapon in player.PlayerPawn.Value.WeaponServices!.MyWeapons) + { + if (weapon is { IsValid:true, Value.IsValid: true } && weapon.Value.DesignerName.Contains("healthshot")) { + giveBack = weapon.Value.DesignerName; + weapon.Value.Remove(); + } + } + // give HealthShot + VirtualFunctions.GiveNamedItem(player.PlayerPawn.Value.ItemServices!.Handle, giveBack, 0, 0, 0, 0); + } +}