-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3441b9a
commit e3de891
Showing
4 changed files
with
123 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} |