From 88345fd19f3738154494d2343eaad7d6a275d356 Mon Sep 17 00:00:00 2001 From: MSWS Date: Sat, 3 Feb 2024 14:49:27 -0800 Subject: [PATCH] Fix color --- mod/Jailbreak.Rebel/RebelManager.cs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/mod/Jailbreak.Rebel/RebelManager.cs b/mod/Jailbreak.Rebel/RebelManager.cs index 5e7e2bc3..c35556e4 100644 --- a/mod/Jailbreak.Rebel/RebelManager.cs +++ b/mod/Jailbreak.Rebel/RebelManager.cs @@ -16,7 +16,7 @@ public void Start(BasePlugin parent) { parent.RegisterEventHandler(OnPlayerDisconnect); parent.RegisterEventHandler(OnRoundStart); - + parent.AddTimer(1f, () => { foreach (var player in GetActiveRebels()) @@ -40,8 +40,11 @@ private HookResult OnRoundStart(EventRoundStart @event, GameEventInfo info) rebelTimes.Clear(); foreach (var player in Utilities.GetPlayers()) { - ApplyRebelColor(player); + if (!player.IsValid) + continue; + ApplyRebelColor(player); } + return HookResult.Continue; } @@ -99,13 +102,10 @@ private void ApplyRebelColor(CCSPlayerController player) { if (!player.IsValid || player.Pawn.Value == null) return; - var percentage = GetRebelTimePercentage(player); - player.PrintToConsole("Rebel percentage: " + percentage); - var inverse = 1 - percentage; - var inverseInt = (int)(inverse * 255); - var color = Color.FromArgb(254, (int) Math.Round(percentage * 255.0), inverseInt, inverseInt); + var percentRGB = (int)Math.Round(GetRebelTimePercentage(player) * 255.0); + var color = Color.FromArgb(254, 255, percentRGB, percentRGB); player.PrintToConsole("Color: " + color.ToString()); - if (percentage <= 0) + if (percentRGB <= 0) { color = Color.FromArgb(254, 255, 255, 255); }