From 4e44b70ac1264c5ea011aca775735b59bbfd2d96 Mon Sep 17 00:00:00 2001 From: WarrentyExpired Date: Sat, 8 Aug 2026 20:32:59 -0400 Subject: [PATCH] #W# Added MoveToLoc command. movetoloc +100 +100 --- Scripts/Commands/MoveToLocation.cs | 53 ++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 Scripts/Commands/MoveToLocation.cs diff --git a/Scripts/Commands/MoveToLocation.cs b/Scripts/Commands/MoveToLocation.cs new file mode 100644 index 0000000..1ce72aa --- /dev/null +++ b/Scripts/Commands/MoveToLocation.cs @@ -0,0 +1,53 @@ +using System; +using Server; +using Server.Commands; + +namespace Server.Commands +{ + public class MoveToLocCommand + { + public static void Initialize() + { + // Registers the command. GMs and Admins can use it. + CommandSystem.Register( "MoveToLoc", AccessLevel.GameMaster, new CommandEventHandler( MoveToLoc_OnCommand ) ); + } + + [Usage( "MoveToLoc [+x/-x] [+y/-y] [+z/-z]" )] + public static void MoveToLoc_OnCommand( CommandEventArgs e ) + { + Mobile from = e.Mobile; + + if ( e.Length < 2 ) + { + from.SendMessage( "Usage: [MoveToLoc [+x/-x] [+y/-y] [+z/-z]" ); + return; + } + + int currentX = from.X; + int currentY = from.Y; + int currentZ = from.Z; + + int targetX = ParseCoordinate( e.GetString( 0 ), currentX ); + int targetY = ParseCoordinate( e.GetString( 1 ), currentY ); + int targetZ = ( e.Length >= 3 ) ? ParseCoordinate( e.GetString( 2 ), currentZ ) : currentZ; + + from.MoveToWorld( new Point3D( targetX, targetY, targetZ ), from.Map ); + } + + private static int ParseCoordinate( string input, int currentVal ) + { + if ( string.IsNullOrEmpty( input ) ) + return currentVal; + + // Check if it starts with a relative modification operator + if ( input.StartsWith( "+" ) || input.StartsWith( "-" ) ) + { + int modifier = Utility.ToInt32( input ); + return currentVal + modifier; + } + + // Otherwise treat it as a standard absolute coordinate + return Utility.ToInt32( input ); + } + } +}