From e3de891b141a75042da67de0e5caf5927aab5875 Mon Sep 17 00:00:00 2001 From: BruteForceMaestro <75899371+BruteForceMaestro@users.noreply.github.com> Date: Fri, 31 Dec 2021 20:56:20 +0600 Subject: [PATCH] big oopsie --- Config.cs | 12 ++++++++++++ EventHandlers.cs | 51 ++++++++++++++++++++++++++++++++++++++++++++++++ HPDisplay.csproj | 29 +++++++++++++++++++++++++++ Main.cs | 31 +++++++++++++++++++++++++++++ 4 files changed, 123 insertions(+) create mode 100644 Config.cs create mode 100644 EventHandlers.cs create mode 100644 HPDisplay.csproj create mode 100644 Main.cs diff --git a/Config.cs b/Config.cs new file mode 100644 index 0000000..4960ed1 --- /dev/null +++ b/Config.cs @@ -0,0 +1,12 @@ +using Exiled.API.Interfaces; +using System.ComponentModel; + +namespace HPDisplay +{ + public class Config : IConfig + { + public bool IsEnabled { get; set; } = true; + [Description("Whether to display the Artificial HP (Armor). Ex.: SCP-173's AHP")] + public bool DisplayAHP { get; set; } = true; + } +} diff --git a/EventHandlers.cs b/EventHandlers.cs new file mode 100644 index 0000000..79d66c3 --- /dev/null +++ b/EventHandlers.cs @@ -0,0 +1,51 @@ +using Exiled.Events.EventArgs; +using Exiled.API.Features; +using System.Collections.Generic; +using MEC; +using System; + +namespace HPDisplay +{ + class EventHandlers + { + public void OnPlayerChangingRoles(ChangingRoleEventArgs ev) + { + Timing.RunCoroutine(HPInfo(ev.Player)); + } + public void OnHurting(HurtingEventArgs ev) + { + Timing.RunCoroutine(HPInfo(ev.Target)); + } + public void OnWaitingForPlayers() + { + Timing.RunCoroutine(HPLoop()); + } + private IEnumerator HPLoop() // this is ugly af, but i have to do this, i haven't found an event that gets called when hp or ahp increases. (adrenaline, medkit, etc.) + { + while (true) + { + foreach (Player player in Player.List) + { + Timing.RunCoroutine(HPInfo(player)); + } + yield return Timing.WaitForSeconds(1f); + } + } + + private IEnumerator HPInfo(Player player) + { + yield return Timing.WaitForOneFrame; // The information about the HP is not fully processed on the call of these events, so we need to wait a frame for things to make sense. + if (player == null || !player.IsAlive) + { + yield break; + } + string info = string.Empty; + if (Main.Instance.Config.DisplayAHP && player.ArtificialHealth > 0) + { + info = $"{Math.Round(player.ArtificialHealth)}/{player.MaxArtificialHealth} AHP\n"; + } + info += $"{Math.Round(player.Health)}/{player.MaxHealth} HP"; + player.CustomInfo = info; + } + } +} diff --git a/HPDisplay.csproj b/HPDisplay.csproj new file mode 100644 index 0000000..7f41d53 --- /dev/null +++ b/HPDisplay.csproj @@ -0,0 +1,29 @@ + + + + net48 + 10.0 + disable + enable + + + + + + + + + ..\..\..\..\Downloads\Exiled.tar\Exiled\Assembly-CSharp.dll + + + D:\SteamLibrary\steamapps\common\SCP Secret Laboratory Dedicated Server\SCPSL_Data\Managed\Assembly-CSharp-firstpass.dll + + + D:\SteamLibrary\steamapps\common\SCP Secret Laboratory Dedicated Server\SCPSL_Data\Managed\Mirror.dll + + + D:\SteamLibrary\steamapps\common\SCP Secret Laboratory Dedicated Server\SCPSL_Data\Managed\UnityEngine.CoreModule.dll + + + + diff --git a/Main.cs b/Main.cs new file mode 100644 index 0000000..5a3e9b4 --- /dev/null +++ b/Main.cs @@ -0,0 +1,31 @@ +using Exiled.API.Features; +using Player = Exiled.Events.Handlers.Player; +using Server = Exiled.Events.Handlers.Server; + +namespace HPDisplay +{ + public class Main : Plugin + { + EventHandlers handlers = new(); + public static Main Instance { get; set; } + + public override void OnEnabled() + { + Instance = this; + handlers = new(); + Player.ChangingRole += handlers.OnPlayerChangingRoles; + Player.Hurting += handlers.OnHurting; + Server.WaitingForPlayers += handlers.OnWaitingForPlayers; + base.OnEnabled(); + } + + public override void OnDisabled() + { + handlers = null; + Player.ChangingRole -= handlers.OnPlayerChangingRoles; + Player.Hurting -= handlers.OnHurting; + Server.WaitingForPlayers -= handlers.OnWaitingForPlayers; + base.OnDisabled(); + } + } +} \ No newline at end of file