diff --git a/Commander/Builtin.py b/Commander/Builtin.py index 40ef823..56ce7ce 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(): @@ -129,15 +137,14 @@ def _ToggleDamageNumbers(): _Position = 0 +_MaxPositions = 6 +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}") @@ -159,15 +166,26 @@ 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) + 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, [None, None, None]) + positions = Positions.CurrentValue.get(mapName, _DefaultPositions()) + positions = _FixPositionsArray(positions) positions[_Position] = _GetPosition(PC()) Positions.CurrentValue[mapName] = positions @@ -179,7 +197,10 @@ def _SavePosition(): def _RestorePosition(): mapName = GetEngine().GetCurrentWorldInfo().GetMapName(True) - position = Positions.CurrentValue.get(mapName, [None, None, None])[_Position] + positions = Positions.CurrentValue.get(mapName, _DefaultPositions()) + positions = _FixPositionsArray(positions) + position = positions[_Position] + if position is None: Popup(f"Position {_Position + 1} Not Saved") @@ -197,16 +218,18 @@ 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 - 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 * 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 if _IsClient(): Commander.Instance.ServerRequestPosition(position, name=None) @@ -214,6 +237,14 @@ def _MoveForward(): 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")) @@ -237,6 +268,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