Skip to content

Commit

Permalink
fix: check if player is alive or controlled before doing certain actions
Browse files Browse the repository at this point in the history
  • Loading branch information
winstxnhdw committed Dec 21, 2023
1 parent 6f9cf9a commit 97fcf29
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lc-hax/Scripts/Commands/ChibakuTenseiCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class ChibakuTenseiCommand : ICommand {
Vector3 spinningY = new(0, 2, 0);

Result TeleportPlayerToRandom(string[] args) {
if (!Helper.GetPlayer(args[0]).IsNotNull(out PlayerControllerB targetPlayer)) {
if (!Helper.GetActivePlayer(args[0]).IsNotNull(out PlayerControllerB targetPlayer)) {
return new Result(message: "Player not found!");
}

Expand Down
2 changes: 1 addition & 1 deletion lc-hax/Scripts/Commands/HateCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public void Execute(string[] args) {
return;
}

if (!Helper.GetPlayer(args[0]).IsNotNull(out PlayerControllerB targetPlayer)) {
if (!Helper.GetActivePlayer(args[0]).IsNotNull(out PlayerControllerB targetPlayer)) {
Console.Print("Player not found!");
return;
}
Expand Down
4 changes: 2 additions & 2 deletions lc-hax/Scripts/Commands/KillCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ void KillPlayer(PlayerControllerB player) =>
player.DamagePlayerFromOtherClientServerRpc(1000, Vector3.zero, -1);

Result KillSelf() {
if (!Helper.LocalPlayer.IsNotNull(out PlayerControllerB localPlayer)) {
if (!Helper.LocalPlayer.IsNotNull(out PlayerControllerB localPlayer) || localPlayer.isPlayerDead) {
return new Result(message: "Player not found!");
}

Expand All @@ -18,7 +18,7 @@ Result KillSelf() {
}

Result KillTargetPlayer(string[] args) {
if (!Helper.GetPlayer(args[0]).IsNotNull(out PlayerControllerB targetPlayer)) {
if (!Helper.GetActivePlayer(args[0]).IsNotNull(out PlayerControllerB targetPlayer)) {
return new Result(message: "Player not found!");
}

Expand Down
2 changes: 1 addition & 1 deletion lc-hax/Scripts/Commands/NoiseCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public void Execute(string[] args) {
return;
}

if (!Helper.GetPlayer(args[0]).IsNotNull(out PlayerControllerB player)) {
if (!Helper.GetActivePlayer(args[0]).IsNotNull(out PlayerControllerB player)) {
Console.Print("Player not found!");
return;
}
Expand Down
2 changes: 1 addition & 1 deletion lc-hax/Scripts/Commands/RandomCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ bool InverseTeleporterExists() {
}

Action TeleportPlayerToRandomLater(string[] args) => () => {
if (!Helper.GetPlayer(args[0]).IsNotNull(out PlayerControllerB targetPlayer)) {
if (!Helper.GetActivePlayer(args[0]).IsNotNull(out PlayerControllerB targetPlayer)) {
Console.Print("Player not found!");
return;
}
Expand Down
7 changes: 7 additions & 0 deletions lc-hax/Scripts/Helpers/Players.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,11 @@ public static partial class Helper {
}

public static PlayerControllerB? GetPlayer(int playerId) => Helper.GetPlayer(playerId.ToString());

public static PlayerControllerB? GetActivePlayer(string playerNameOrId) =>
!Helper.GetPlayer(playerNameOrId).IsNotNull(out PlayerControllerB player)
? null
: player.isPlayerDead ? null : !player.isPlayerControlled ? null : player;

public static PlayerControllerB? GetActivePlayer(int playerId) => Helper.GetActivePlayer(playerId.ToString());
}
2 changes: 1 addition & 1 deletion lc-hax/Scripts/Modules/PhantomMod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ void LookAtPlayer(int indexChange) {
int playerCount = Helper.Players?.Length ?? 0;
this.CurrentSpectatorIndex = (this.CurrentSpectatorIndex + indexChange) % playerCount;

if (!Helper.GetPlayer(this.CurrentSpectatorIndex).IsNotNull(out PlayerControllerB targetPlayer)) {
if (!Helper.GetActivePlayer(this.CurrentSpectatorIndex).IsNotNull(out PlayerControllerB targetPlayer)) {
Console.Print("Player not found!");
return;
}
Expand Down

0 comments on commit 97fcf29

Please sign in to comment.