Skip to content

Commit

Permalink
Dev (#17)
Browse files Browse the repository at this point in the history
* Bump version

* Add rebel module

* Merge feat/rebel

* Fix dict functions, add repeat flag

* Fix types

* Debug color

* Properly round

* Fix color

* Update locale

* Dialects are not languages

* Update state

* Fix color delay

* Fix warden coloring

* Bump version

* Remove debug

* Merge rebel

* Start work on warden laser (#13)

* Merge wardenlaser

* Feat/logs (#14)

* Start work on logs

* More work on logs

* Feat/warden laser (#15)

* Start work on warden laser

* Working commit

* Add warden beam

* Improvements to drawing

* merge logs

* Fix circular dependency

* Log more things

* Bump version

* Remove Z axis check

* Add connection checks
  • Loading branch information
MSWS authored Feb 5, 2024
1 parent de77472 commit 224fd3c
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 15 deletions.
7 changes: 4 additions & 3 deletions mod/Jailbreak.Logs/LogsListeners.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using CounterStrikeSharp.API;
using CounterStrikeSharp.API.Core;
using Jailbreak.Public.Behaviors;
using Jailbreak.Public.Extensions;
using Jailbreak.Public.Mod.Logs;

namespace Jailbreak.Logs;
Expand Down Expand Up @@ -43,7 +44,7 @@ private HookResult OnButtonPressed(CEntityIOOutput output, string name, CEntityI
private HookResult OnGrenadeThrown(EventGrenadeThrown @event, GameEventInfo info)
{
var player = @event.Userid;
if (!player.IsValid)
if (!player.IsReal())
return HookResult.Continue;
var grenade = @event.Weapon;

Expand All @@ -55,11 +56,11 @@ private HookResult OnGrenadeThrown(EventGrenadeThrown @event, GameEventInfo info
private HookResult OnPlayerHurt(EventPlayerHurt @event, GameEventInfo info)
{
var player = @event.Userid;
if (!player.IsValid)
if (!player.IsReal())
return HookResult.Continue;
var attacker = @event.Attacker;

bool isWorld = attacker == null || !attacker.IsValid;
bool isWorld = attacker == null || !attacker.IsReal();
int health = @event.Health;

if (isWorld)
Expand Down
4 changes: 2 additions & 2 deletions mod/Jailbreak.Logs/LogsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ private HookResult OnRoundEnd(EventRoundEnd @event, GameEventInfo info)
{
foreach (var player in Utilities.GetPlayers())
{
if (!player.IsValid || player.IsBot || player.IsHLTV)
if(!player.IsReal())
continue;
foreach (var log in _logMessages)
{
Expand Down Expand Up @@ -89,7 +89,7 @@ public void PrintLogs(CCSPlayerController? player)
{
printLogs(Server.PrintToConsole);
}
else if (player.IsValid && !player.IsBot && !player.IsHLTV)
else if (player.IsReal())
{
printLogs(player.PrintToConsole);
}
Expand Down
4 changes: 2 additions & 2 deletions mod/Jailbreak.Rebel/RebelListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ public void Start(BasePlugin parent)
HookResult OnPlayerHurt(EventPlayerHurt @event, GameEventInfo info)
{
var player = @event.Userid;
if (!player.IsValid)
if (!player.IsReal())
return HookResult.Continue;
if (player.GetTeam() != CsTeam.CounterTerrorist)
return HookResult.Continue;

var attacker = @event.Attacker;
if (!attacker.IsValid)
if (!attacker.IsReal())
return HookResult.Continue;

if (attacker.GetTeam() != CsTeam.Terrorist)
Expand Down
7 changes: 4 additions & 3 deletions mod/Jailbreak.Rebel/RebelManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Jailbreak.Formatting.Extensions;
using Jailbreak.Formatting.Views;
using Jailbreak.Public.Behaviors;
using Jailbreak.Public.Extensions;
using Jailbreak.Public.Mod.Logs;
using Jailbreak.Public.Mod.Rebel;

Expand All @@ -32,7 +33,7 @@ public void Start(BasePlugin parent)
{
foreach (var player in GetActiveRebels())
{
if (!player.IsValid)
if (!player.IsReal())
continue;

if (GetRebelTimeLeft(player) <= 0)
Expand All @@ -51,7 +52,7 @@ HookResult OnRoundStart(EventRoundStart @event, GameEventInfo info)
rebelTimes.Clear();
foreach (var player in Utilities.GetPlayers())
{
if (!player.IsValid)
if (!player.IsReal())
continue;
ApplyRebelColor(player);
}
Expand Down Expand Up @@ -118,7 +119,7 @@ private float GetRebelTimePercentage(CCSPlayerController player)

private void ApplyRebelColor(CCSPlayerController player)
{
if (!player.IsValid || player.Pawn.Value == null)
if (!player.IsReal() || player.Pawn.Value == null)
return;
var percent = GetRebelTimePercentage(player);
var percentRGB = 255 - (int)Math.Round(percent * 255.0);
Expand Down
4 changes: 2 additions & 2 deletions mod/Jailbreak.Teams/Queue/QueueBehavior.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public void ForceGuard(CCSPlayerController player)
/// <returns></returns>
public HookResult OnRequestToJoinTeam(CCSPlayerController? invoked, CommandInfo command)
{
if (invoked == null || !invoked.IsValid)
if(invoked == null || !invoked.IsReal())
return HookResult.Continue;

var state = _state.Get(invoked);
Expand Down Expand Up @@ -174,7 +174,7 @@ public HookResult OnRequestToJoinTeam(CCSPlayerController? invoked, CommandInfo
public HookResult OnPlayerSpawn(EventPlayerSpawn ev, GameEventInfo info)
{
var player = ev.Userid;
if (!player.IsValid)
if (!player.IsReal())
return HookResult.Continue;

var state = _state.Get(ev.Userid);
Expand Down
4 changes: 2 additions & 2 deletions mod/Jailbreak.Warden/Paint/WardenPaintBehavior.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ private void Paint()
return;

var warden = _warden.Warden;
if (warden == null || !warden.IsValid)
if (warden == null || !warden.IsReal())
return;

if ((warden.Buttons & PlayerButtons.Use) == 0)
Expand All @@ -54,7 +54,7 @@ private void Paint()
}

_lastPosition = position;
if (start.DistanceSquared(position) > 150 * 150 || start.Z - position.Z > 0.001f)
if (start.DistanceSquared(position) > 150 * 150)
{
start = position;
}
Expand Down
17 changes: 17 additions & 0 deletions public/Jailbreak.Public/Extensions/PlayerExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,21 @@ public static CsTeam GetTeam(this CCSPlayerController controller)
{
return (CsTeam)controller.TeamNum;
}

public static bool IsReal(this CCSPlayerController player)
{
// Do nothing else before this:
// Verifies the handle points to an entity within the global entity list.
if (!player.IsReal())
return false;

if(player.Connected != PlayerConnectedState.PlayerConnected)
return false;

if (player.IsBot || player.IsHLTV)
return false;

return true;
}

}
3 changes: 2 additions & 1 deletion public/Jailbreak.Public/Mod/Warden/IWardenService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using CounterStrikeSharp.API.Core;
using Jailbreak.Public.Extensions;

namespace Jailbreak.Public.Mod.Warden;

Expand All @@ -14,7 +15,7 @@ public interface IWardenService

bool IsWarden(CCSPlayerController? player)
{
if (player == null || !player.IsValid)
if (player == null || !player.IsReal())
return false;
return HasWarden && Warden != null && Warden.Slot == player.Slot;
}
Expand Down

0 comments on commit 224fd3c

Please sign in to comment.