Skip to content

Commit

Permalink
1.7.0 | SCP-1576 Timer & Micro Energy Status
Browse files Browse the repository at this point in the history
  • Loading branch information
Vretu-Dev committed Oct 14, 2024
1 parent 7155e31 commit ac75aa7
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 2 deletions.
3 changes: 3 additions & 0 deletions UsefulHints/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ public class Config : IConfig
public float Scp268Duration { get; set; } = 15f;
public string Scp268TimeLeftMessage { get; set; } = "Remaining: {0}s";
public string Scp2176TimeLeftMessage { get; set; } = "Remaining: {0}s";
public string Scp1576TimeLeftMessage { get; set; } = "Remaining: {0}s";
public string JailbirdUseMessage { get; set; } = "Remaining charges: {0}";
public string MicroEnergyMessage { get; set; } = "Remaining energy: {0}%";
public string MicroLowEnergyMessage { get; set; } = "Low Energy";
public string Scp207HintMessage { get; set; } = "You have {0} doses of SCP-207";
public string AntiScp207HintMessage { get; set; } = "You have {0} doses of Anti SCP-207";
[Description("Item Warnings:")]
Expand Down
72 changes: 71 additions & 1 deletion UsefulHints/EventHandlers/Items/Hints.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Linq;
using System;
using System.Linq;
using System.Collections.Generic;
using Exiled.API.Enums;
using Exiled.API.Extensions;
Expand All @@ -17,7 +18,10 @@ public static class Hints
private static Dictionary<Player, ItemType> activeItems = new Dictionary<Player, ItemType>();
public static void RegisterEvents()
{
Exiled.Events.Handlers.Player.PickingUpItem += OnPickingUpMicroHid;
Exiled.Events.Handlers.Player.PickingUpItem += OnPickingUpSCP207;
Exiled.Events.Handlers.Player.UsedItem += OnSCP1576Used;
Exiled.Events.Handlers.Player.ChangedItem += OnSCP1576ChangedItem;
Exiled.Events.Handlers.Player.UsedItem += OnSCP268Used;
Exiled.Events.Handlers.Player.InteractingDoor += OnSCP268Interacting;
Exiled.Events.Handlers.Player.ChangedItem += OnSCP268ChangedItem;
Expand All @@ -27,14 +31,39 @@ public static void RegisterEvents()
}
public static void UnregisterEvents()
{
Exiled.Events.Handlers.Player.PickingUpItem -= OnPickingUpMicroHid;
Exiled.Events.Handlers.Player.PickingUpItem -= OnPickingUpSCP207;
Exiled.Events.Handlers.Player.UsedItem -= OnSCP1576Used;
Exiled.Events.Handlers.Player.ChangedItem -= OnSCP1576ChangedItem;
Exiled.Events.Handlers.Player.UsedItem -= OnSCP268Used;
Exiled.Events.Handlers.Player.InteractingDoor -= OnSCP268Interacting;
Exiled.Events.Handlers.Player.ChangedItem -= OnSCP268ChangedItem;
Exiled.Events.Handlers.Map.ExplodingGrenade -= OnSCP2176Grenade;
Exiled.Events.Handlers.Server.WaitingForPlayers -= OnWaitingForPlayers;
Exiled.Events.Handlers.Player.PickingUpItem -= OnPickingUpJailbird;
}
private static void OnPickingUpMicroHid(PickingUpItemEventArgs ev)
{
if (ev.Pickup.Type == ItemType.MicroHID)
{
var microHidPickup = ev.Pickup.Base as InventorySystem.Items.MicroHID.MicroHIDPickup;

if (microHidPickup != null)
{
float energyPercentage = microHidPickup.Energy * 100;
float roundedEnergyPercentage = (float)Math.Round(energyPercentage, 1);

if (roundedEnergyPercentage < 5)
{
ev.Player.ShowHint($"<color=red>{string.Format(UsefulHints.Instance.Config.MicroLowEnergyMessage)}</color>", 4);
}
else
{
ev.Player.ShowHint($"<color=#4169E1>{string.Format(UsefulHints.Instance.Config.MicroEnergyMessage, roundedEnergyPercentage)}</color>", 4);
}
}
}
}
// SCP 207 Handler
private static void OnPickingUpSCP207(PickingUpItemEventArgs ev)
{
Expand All @@ -57,6 +86,47 @@ private static void OnPickingUpSCP207(PickingUpItemEventArgs ev)
}
}
}
// SCP 1576 Handler
private static void OnSCP1576Used(UsedItemEventArgs ev)
{
if (ev.Item.Type == ItemType.SCP1576)
{
if (activeCoroutines.TryGetValue(ev.Player, out var existingCoroutine))
{
Timing.KillCoroutines(existingCoroutine);
activeCoroutines.Remove(ev.Player);
}
if (activeItems.ContainsKey(ev.Player))
{
activeItems.Remove(ev.Player);
}

var coroutine = Timing.RunCoroutine(Scp1576Timer(ev.Player));
activeCoroutines[ev.Player] = coroutine;
activeItems[ev.Player] = ev.Item.Type;
}
}
private static void OnSCP1576ChangedItem(ChangedItemEventArgs ev)
{
if (activeCoroutines.ContainsKey(ev.Player) && activeItems.ContainsKey(ev.Player) && activeItems[ev.Player] == ItemType.SCP1576)
{
Timing.KillCoroutines(activeCoroutines[ev.Player]);
activeCoroutines.Remove(ev.Player);
activeItems.Remove(ev.Player);
}
}
private static IEnumerator<float> Scp1576Timer(Player player)
{
float duration = 30f;

while (duration > 0)
{
player.ShowHint($"<color=#FFA500>{new string('\n', 10)}{string.Format(UsefulHints.Instance.Config.Scp1576TimeLeftMessage, (int)duration)}</color>", 1.15f);
yield return Timing.WaitForSeconds(1f);
duration -= 1f;
}
activeCoroutines.Remove(player);
}
// SCP 268 Handler
private static void OnSCP268Used(UsedItemEventArgs ev)
{
Expand Down
2 changes: 1 addition & 1 deletion UsefulHints/UsefulHints.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class UsefulHints : Plugin<Config>
public override string Name => "Useful Hints";
public override string Author => "Vretu";
public override string Prefix { get; } = "UH";
public override Version Version => new Version(1, 6, 3);
public override Version Version => new Version(1, 7, 0);
public override Version RequiredExiledVersion { get; } = new Version(8, 9, 8);
public override PluginPriority Priority { get; } = PluginPriority.Low;
public static UsefulHints Instance { get; private set; }
Expand Down

0 comments on commit ac75aa7

Please sign in to comment.