Here's a basic script I wrote to test the idea. It's a pretty basic script that checks the available modules on the ship, attempts to use the scanner, finds the nearest asteroid, then gets within mining range.
6 var distance = 10.0;
7 var target = null;
8
9 var main = function() {
10
11 //
12 // mine target if in range //////////////////////////////////////////////////
13 //
14
15 if(target != null) {
16 if(Ship.distance(target) <= distance + 1) {
17 Ship.navigation.Stop();
18 Ship.Log("Activate lasers!");
19 return;
20 }
21 else {
22 Ship.navigation.Approach(target, distance);
23 }
24 }
25
26 //
27 // if no target, scan ///////////////////////////////////////////////////////
28 //
29
30 var scanners = Ship.GetModulesOfType(ModuleType.Sensor);
31 if(scanners.Count > 0)
32 {
33 var scanner = scanners[0];
34 scanner.Activate(function(scanResults) {
35 var locals = scanResults;
36
37 if(locals == null) {
38 return;
39 }
40
41 Ship.Log("Locals: " + locals.length);
42
43 for(var index in locals) {
44 var local = locals[index];
45 if(local.type == LocalType.Asteroid) {
46 target = local;
47 break;
48 }
49 }
50 });
51 }
52 }
The hardest part of this project was sanitizing and wrapping all the interfaces to be made available to the script. You have to be very careful not to expose interfaces that will allow the player to do unexpected things. You need very tight API and interface controls.
Of course, you can control your ship and modules as well, using the same API form the in game GUI.
Accessing the module API from a GUI