Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Whip's GPS Waypoint Distance Script v1 - revision: 3/30/16
- /*
- Instructions:
- 1) Add this script onto your ship
- 2) Name a block on your ship "Reference"
- 3) Copy paste your GPS coordinate into the argument and hit run
- If you do it manually, the form is GPS:[Name of waypoint]:[x]:[y]:[z]:
- 4) Read the program's readout for the distance to waypoint :D
- Code by Whiplash141
- */
- string strReferenceName = "Reference"; //name of block that we are using to measure distance, can be any terminal block
- void Main( string arg )
- {
- Echo( "WMI Waypoint Distance Script\n" );
- List<IMyTerminalBlock> listReferences = new List<IMyTerminalBlock>();
- GridTerminalSystem.SearchBlocksOfName( strReferenceName, listReferences );
- IMyTerminalBlock referenceBlock = listReferences[0];
- Vector3D shipPositionVec;
- if( referenceBlock == null ) //checks for reference block to measure distance from
- {
- Echo("Error: No reference block named " + strReferenceName + " was found");
- return;
- }else{
- shipPositionVec = referenceBlock.GetPosition();
- }
- if( !arg.ToLower().Contains( "gps" ) ) //checks if we have the correct naming
- {
- Echo("Error: GPS coordinate " + arg
- + " could not be understod\nPlease input coordinates in the form\nGPS:[Name of waypoint]:[x]:[y]:[z]:");
- return;
- }
- string[] split_arg = arg.Split(':'); //splits argument at the colons
- if( split_arg.Length < 5 )
- {
- Echo("Error: GPS coordinate " + arg
- + " could not be understod\nPlease input coordinates in the form\nGPS:[Name of waypoint]:[x]:[y]:[z]:");
- return;
- }else{
- string strWaypointName = split_arg[1];
- Vector3D waypointVec;
- waypointVec.X = StringToDouble( split_arg[2] );
- waypointVec.Y = StringToDouble( split_arg[3] );
- waypointVec.Z = StringToDouble( split_arg[4] );
- double distance = Math.Round( Vector3D.Distance( waypointVec, shipPositionVec ), 2 );
- Echo( "Distance from Waypoint '" + strWaypointName + "': "
- + distance.ToString() + " meters" );
- }
- }
- double StringToDouble( string value )
- {
- double n;
- bool isDouble = double.TryParse(value, out n);
- if (isDouble)
- return n;
- else
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement