Skip to content

Commit

Permalink
big oopsie
Browse files Browse the repository at this point in the history
  • Loading branch information
BruteForceMaestro authored Dec 31, 2021
1 parent 3441b9a commit e3de891
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 0 deletions.
12 changes: 12 additions & 0 deletions Config.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}
51 changes: 51 additions & 0 deletions EventHandlers.cs
Original file line number Diff line number Diff line change
@@ -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<float> 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<float> 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;
}
}
}
29 changes: 29 additions & 0 deletions HPDisplay.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net48</TargetFramework>
<LangVersion>10.0</LangVersion>
<ImplicitUsings>disable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="EXILED" Version="4.1.7" />
</ItemGroup>

<ItemGroup>
<Reference Include="Assembly-CSharp">
<HintPath>..\..\..\..\Downloads\Exiled.tar\Exiled\Assembly-CSharp.dll</HintPath>
</Reference>
<Reference Include="Assembly-CSharp-firstpass">
<HintPath>D:\SteamLibrary\steamapps\common\SCP Secret Laboratory Dedicated Server\SCPSL_Data\Managed\Assembly-CSharp-firstpass.dll</HintPath>
</Reference>
<Reference Include="Mirror">
<HintPath>D:\SteamLibrary\steamapps\common\SCP Secret Laboratory Dedicated Server\SCPSL_Data\Managed\Mirror.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.CoreModule">
<HintPath>D:\SteamLibrary\steamapps\common\SCP Secret Laboratory Dedicated Server\SCPSL_Data\Managed\UnityEngine.CoreModule.dll</HintPath>
</Reference>
</ItemGroup>

</Project>
31 changes: 31 additions & 0 deletions Main.cs
Original file line number Diff line number Diff line change
@@ -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<Config>
{
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();
}
}
}

0 comments on commit e3de891

Please sign in to comment.