From 83002b45dc91b98bae466323d05b2889dc7fd46c Mon Sep 17 00:00:00 2001 From: Grim Reader Date: Mon, 1 Apr 2024 20:00:18 +0530 Subject: [PATCH 1/5] Patch to Stop Player's Motion on Teleport --- Commander/Builtin.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Commander/Builtin.py b/Commander/Builtin.py index 40ef823..5a85e14 100644 --- a/Commander/Builtin.py +++ b/Commander/Builtin.py @@ -150,6 +150,11 @@ def _GetPosition(PC): } +def _StopPlayer(PC): + PlayerPawn = PC.Pawn + PlayerPawn.Velocity = 0, 0, 0 + + def ApplyPosition(PC, position): location = position["X"], position["Y"], position["Z"] rotation = position["Pitch"], position["Yaw"], 0 @@ -208,6 +213,8 @@ def _MoveForward(): position["X"] += math.cos(yaw) * math.cos(pitch) * 250 position["Y"] += math.sin(yaw) * math.cos(pitch) * 250 + _StopPlayer(PC()) + if _IsClient(): Commander.Instance.ServerRequestPosition(position, name=None) else: From 3ddb7cca9297c935779514856dda81984b1eacfa Mon Sep 17 00:00:00 2001 From: Grim Reader Date: Mon, 1 Apr 2024 22:36:04 +0530 Subject: [PATCH 2/5] Patch to add a slider for the 'Move Forward' command. --- Commander/Builtin.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/Commander/Builtin.py b/Commander/Builtin.py index 5a85e14..4be8a02 100644 --- a/Commander/Builtin.py +++ b/Commander/Builtin.py @@ -24,6 +24,14 @@ Choices=["Allow", "With Host", "None"], StartingValue="Allow" ) +ClientTeleportingDistance: ModMenu.Options.Slider = ModMenu.Options.Slider( + Caption="Client Teleporting Distance", + Description="Specifies the distance the user can teleport, using the 'Move Forward' command.", + StartingValue=250, + MinValue=250, + MaxValue=25000, + Increment=250 +) ClientSpeedPermissions: ModMenu.Options.Boolean = ModMenu.Options.Boolean( Caption="Client Speed Permissions", Description="Should clients in multiplayer be allowed to modify the speed of the game.", @@ -32,7 +40,7 @@ Options: Sequence[ModMenu.Options.Base] = ( - Positions, DamageNumbers, ClientTeleporting, ClientSpeedPermissions + Positions, DamageNumbers, ClientTeleporting, ClientTeleportingDistance, ClientSpeedPermissions ) def PC(): @@ -209,9 +217,11 @@ def _MoveForward(): pitch = position["Pitch"] / 65535 * math.tau yaw = position["Yaw" ] / 65535 * math.tau - position["Z"] += math.sin(pitch) * 250 - position["X"] += math.cos(yaw) * math.cos(pitch) * 250 - position["Y"] += math.sin(yaw) * math.cos(pitch) * 250 + distance = ClientTeleportingDistance.CurrentValue + + position["Z"] += math.sin(pitch) * distance + position["X"] += math.cos(yaw) * math.cos(pitch) * distance + position["Y"] += math.sin(yaw) * math.cos(pitch) * distance _StopPlayer(PC()) From bf891bd85b82fbf9e0d01c0878efb31790747166 Mon Sep 17 00:00:00 2001 From: Grim Reader Date: Sun, 6 Oct 2024 19:31:10 +0530 Subject: [PATCH 3/5] Patch to add move backwards with refactoring --- Commander/Builtin.py | 38 +++++++++++++++++++++++--------------- Commander/Commander.py | 2 +- 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/Commander/Builtin.py b/Commander/Builtin.py index 4be8a02..4a99fc8 100644 --- a/Commander/Builtin.py +++ b/Commander/Builtin.py @@ -137,15 +137,14 @@ def _ToggleDamageNumbers(): _Position = 0 +_MaxPositions = 5 +def _DefaultPositions(): + global _MaxPositions + return [None] * _MaxPositions def _SelectPosition(): - global _Position - if _Position == 0: - _Position = 1 - elif _Position == 1: - _Position = 2 - elif _Position == 2: - _Position = 0 + global _Position, _MaxPositions + _Position = _Position + 1 % _MaxPositions Popup(f"Selected Position {_Position + 1}") @@ -172,15 +171,17 @@ def ApplyPosition(PC, position): PC.NoFailSetPawnLocation(PC.Pawn, location) else: pawn = vehicle.GetPawnToTeleport() - pawn.Mesh.SetRBPosition(location); - pawn.Mesh.SetRBRotation(rotation); + pawn.Mesh.SetRBPosition(location) + pawn.Mesh.SetRBRotation(rotation) PC.ClientSetRotation(rotation) + _StopPlayer(PC()) + def _SavePosition(): mapName = GetEngine().GetCurrentWorldInfo().GetMapName(True) - positions = Positions.CurrentValue.get(mapName, [None, None, None]) + positions = Positions.CurrentValue.get(mapName, _DefaultPositions()) positions[_Position] = _GetPosition(PC()) Positions.CurrentValue[mapName] = positions @@ -192,7 +193,7 @@ def _SavePosition(): def _RestorePosition(): mapName = GetEngine().GetCurrentWorldInfo().GetMapName(True) - position = Positions.CurrentValue.get(mapName, [None, None, None])[_Position] + position = Positions.CurrentValue.get(mapName, _DefaultPositions())[_Position] if position is None: Popup(f"Position {_Position + 1} Not Saved") @@ -210,27 +211,33 @@ def _RestorePosition(): Commander.Instance.ClientApplyPosition(position, name="") -def _MoveForward(): +def _Move(direction = 1): position = _GetPosition(PC()) # Convert our pitch and yaw from the game's units to radians. pitch = position["Pitch"] / 65535 * math.tau yaw = position["Yaw" ] / 65535 * math.tau - distance = ClientTeleportingDistance.CurrentValue + distance = ClientTeleportingDistance.CurrentValue * direction position["Z"] += math.sin(pitch) * distance position["X"] += math.cos(yaw) * math.cos(pitch) * distance position["Y"] += math.sin(yaw) * math.cos(pitch) * distance - _StopPlayer(PC()) - if _IsClient(): Commander.Instance.ServerRequestPosition(position, name=None) else: ApplyPosition(PC(), position) +def _MoveForward(): + return _Move() + + +def _MoveBackward(): + return _Move(-1) + + def ApplyPlayersOnly(playersOnly): GetEngine().GetCurrentWorldInfo().bPlayersOnly = playersOnly Popup("World Freeze: " + ("On" if playersOnly else "Off")) @@ -254,6 +261,7 @@ def _TogglePlayersOnly(): ModMenu.Keybind("Restore Position", "Comma", OnPress=_RestorePosition ), ModMenu.Keybind("Select Position", "Slash", OnPress=_SelectPosition ), ModMenu.Keybind("Teleport Forward", "Up", OnPress=_MoveForward ), + ModMenu.Keybind("Teleport Backward", "Down", OnPress=_MoveBackward ) ) def KeybindExists(name: str) -> bool: diff --git a/Commander/Commander.py b/Commander/Commander.py index f257507..750f843 100644 --- a/Commander/Commander.py +++ b/Commander/Commander.py @@ -62,7 +62,7 @@ def CompileCustomCommand(command: str) -> Callable[[], None]: class Commander(ModMenu.SDKMod): Name: str = "Commander" - Version: str = "2.5" + Version: str = "2.6" Description: str = "Perform various actions in game using key bindings." Author: str = "mopioid" Types: ModMenu.ModTypes = ModMenu.ModTypes.Gameplay From df62c5c86bc3423c544c37df4fa2091dae42011f Mon Sep 17 00:00:00 2001 From: Grim Reader Date: Sun, 6 Oct 2024 19:35:12 +0530 Subject: [PATCH 4/5] Modulus bug fix --- Commander/Builtin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Commander/Builtin.py b/Commander/Builtin.py index 4a99fc8..9b41746 100644 --- a/Commander/Builtin.py +++ b/Commander/Builtin.py @@ -144,7 +144,7 @@ def _DefaultPositions(): def _SelectPosition(): global _Position, _MaxPositions - _Position = _Position + 1 % _MaxPositions + _Position = (_Position + 1) % _MaxPositions Popup(f"Selected Position {_Position + 1}") From c80cf97c2fbf667037d2de5a4fa99f87484e4c48 Mon Sep 17 00:00:00 2001 From: Grim Reader Date: Sun, 6 Oct 2024 20:11:32 +0530 Subject: [PATCH 5/5] Allowing the user to change the number of saved locations. --- Commander/Builtin.py | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/Commander/Builtin.py b/Commander/Builtin.py index 9b41746..56ce7ce 100644 --- a/Commander/Builtin.py +++ b/Commander/Builtin.py @@ -137,7 +137,7 @@ def _ToggleDamageNumbers(): _Position = 0 -_MaxPositions = 5 +_MaxPositions = 6 def _DefaultPositions(): global _MaxPositions return [None] * _MaxPositions @@ -157,11 +157,6 @@ def _GetPosition(PC): } -def _StopPlayer(PC): - PlayerPawn = PC.Pawn - PlayerPawn.Velocity = 0, 0, 0 - - def ApplyPosition(PC, position): location = position["X"], position["Y"], position["Z"] rotation = position["Pitch"], position["Yaw"], 0 @@ -175,13 +170,22 @@ def ApplyPosition(PC, position): pawn.Mesh.SetRBRotation(rotation) PC.ClientSetRotation(rotation) - _StopPlayer(PC()) + PlayerPawn = PC.Pawn + PlayerPawn.Velocity = 0, 0, 0 + + +def _FixPositionsArray(positions): + global _MaxPositions + if len(positions) < _MaxPositions: + positions = positions + ([None] * (_MaxPositions - len(positions))) + return positions def _SavePosition(): mapName = GetEngine().GetCurrentWorldInfo().GetMapName(True) positions = Positions.CurrentValue.get(mapName, _DefaultPositions()) + positions = _FixPositionsArray(positions) positions[_Position] = _GetPosition(PC()) Positions.CurrentValue[mapName] = positions @@ -193,7 +197,10 @@ def _SavePosition(): def _RestorePosition(): mapName = GetEngine().GetCurrentWorldInfo().GetMapName(True) - position = Positions.CurrentValue.get(mapName, _DefaultPositions())[_Position] + positions = Positions.CurrentValue.get(mapName, _DefaultPositions()) + positions = _FixPositionsArray(positions) + position = positions[_Position] + if position is None: Popup(f"Position {_Position + 1} Not Saved")