Also, sometimes our script have other missclick and open solar info instead of Jump throught stargate:
This window will be known as WindowOther:
To close this window, we must hover the mouse cursor. Then there will be 3 buttons in header. We need click to Close button.
Let’s write a function to close this window.
public void CloseWindowOther()
{
Host.Log("close WindowOther");
var windowOther = Sanderling?.MemoryMeasurementParsed?.Value?.WindowOther?.FirstOrDefault();
// if close button not visible then move mouse to the our window
if(!windowOther.HeaderButtonsVisible ?? false)
Sanderling.MouseMove(windowOther.LabelText.FirstOrDefault());
Sanderling.InvalidateMeasurement(); // make sure we have new measurement
if(windowOther.HeaderButton != null)
{
// we have 3 buttons and looking with HintText "Close"
var closeButton = windowOther.HeaderButton?.FirstOrDefault(x => x.HintText == "Close");
if(closeButton !=null)
Sanderling.MouseClickLeft(closeButton);
}
}
I think enough for the first time. Save the resulting script:
Full code for Terpla autopilot script
/* Autopilot improved by Terpla. Version TPAutopilot-2018-05-31v1
Features:
-plays sound if ship docked
-toggles InfoPanelRoute if no route found
-closes system info window if it was opened by misstake
*/
/*
This is a warp to 0km auto-pilot, making your travels faster and thus safer by directly warping to gates/stations.
The bot follows the route set in the in-game autopilot and uses the context menu to initiate warp and dock commands.
To use the bot, set the in-game autopilot route before starting the bot.
Make sure you are undocked before starting the bot because the bot does not undock.
*/
while(true)
{
var Measurement = Sanderling?.MemoryMeasurementParsed?.Value;
var ManeuverType = Measurement?.ShipUi?.Indication?.ManeuverType;
if(Measurement.IsDocked ?? true)
{
// play sound if we docked
Console.Beep(500, 200);
Host.Delay(6000);
goto loop;
}
if(Measurement.WindowOther != null) CloseWindowOther();
if(ShipManeuverTypeEnum.Warp == ManeuverType ||
ShipManeuverTypeEnum.Jump == ManeuverType)
goto loop; // do nothing while warping or jumping.
// from the set of route element markers in the Info Panel pick the one that represents the next Waypoint/System.
// We assume this is the one which is nearest to the topleft corner of the Screen which is at (0,0)
var RouteElementMarkerNext =
Measurement?.InfoPanelRoute?.RouteElementMarker
?.OrderByCenterDistanceToPoint(new Vektor2DInt(0, 0))?.FirstOrDefault();
if(null == RouteElementMarkerNext)
{
Host.Log("no route found in info panel.");
// Let's try toggle expand button
var toogleButton = Measurement?.InfoPanelRoute?.ExpandToggleButton;
if(toogleButton !=null) Sanderling.MouseClickLeft(toogleButton);
goto loop;
}
// rightclick the marker to open the contextmenu.
Sanderling.MouseClickRight(RouteElementMarkerNext);
// retrieve a new measurement.
Measurement = Sanderling?.MemoryMeasurementParsed?.Value;
// from the first menu, pick the first entry that contains "dock" or "jump".
var MenuEntry =
Measurement?.Menu?.FirstOrDefault()
?.Entry?.FirstOrDefault(candidate => candidate.Text.RegexMatchSuccessIgnoreCase("dock|jump"));
if(null == MenuEntry)
{
Host.Log("no suitable menu entry found.");
goto loop;
}
Host.Log("menu entry found. clicking to initiate warp.");
Sanderling.MouseClickLeft(MenuEntry);
loop:
// wait for four seconds before repeating.
Host.Delay(4000);
// make sure new measurement will be taken.
Sanderling.InvalidateMeasurement();
}
public void CloseWindowOther()
{
Host.Log("close WindowOther");
var windowOther = Sanderling?.MemoryMeasurementParsed?.Value?.WindowOther?.FirstOrDefault();
// if close button not visible then move mouse to the our window
if(!windowOther.HeaderButtonsVisible ?? false)
Sanderling.MouseMove(windowOther.LabelText.FirstOrDefault());
Sanderling.InvalidateMeasurement(); // make sure we have new measurement
if(windowOther.HeaderButton != null)
{
// we have 3 buttons and looking with HintText "Close"
var closeButton = windowOther.HeaderButton?.FirstOrDefault(x => x.HintText == "Close");
if(closeButton !=null)
Sanderling.MouseClickLeft(closeButton);
}
}
I do not think that you can earn a lot of money on transportation missions, but this autopilot is useful if you are driving a large ship for a long distance. We also learned the basics for writing improvements to default scripts.