Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 48 additions & 16 deletions Commander/Builtin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand All @@ -32,7 +40,7 @@


Options: Sequence[ModMenu.Options.Base] = (
Positions, DamageNumbers, ClientTeleporting, ClientSpeedPermissions
Positions, DamageNumbers, ClientTeleporting, ClientTeleportingDistance, ClientSpeedPermissions
)

def PC():
Expand Down Expand Up @@ -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}")


Expand All @@ -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
Expand All @@ -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")

Expand All @@ -197,23 +218,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

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)
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"))
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion Commander/Commander.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down