Space Engineers

Space Engineers

Not enough ratings
GPS Ingame Scripting API - Example (old)
   
Award
Favorite
Favorited
Unfavorite
File Size
Posted
Updated
375.744 KB
17 Jan, 2018 @ 3:43pm
28 Jul, 2021 @ 5:02am
6 Change Notes ( view )

Subscribe to download
GPS Ingame Scripting API - Example (old)

Description
An example of how to use the GPS Ingame Scripting API.
Keeps a gps marker at the position of the executing block.

GPSInterface Documentation
Crossed out methods are obsolete, but still available for backwards compatibility.
class GPSInterface

GPSInterface(IMyTerminalBlock)
Initializes the GPSInterface with the specified custom data block.

AddGps(string name, Vector3D position, string description , bool persistent, bool showOnHud): Future_Integer
AddLocalGps(string name, Vector3D position, string description , bool persistent, bool showOnHud): Future_Integer
Creates a new gps marker.

Clear(): Future_Boolean
Deletes all gps markers created by this custom data block.

EditGps(int id, Vector3D position): Future_Integer
Moves a gps marker.

GetInterfaceBlock(): IMyTerminalBlock
Returns the custom data block.

IsActive(): Future_Boolean
Checks if the mod is active. If the mod is used the future returns true, if not it will never finish.

List(): Future_List
Returns all non-persistent GPS markers created by this custom data block.

RemoveGps(int id): Future_Boolean
RemoveLocalGps(int id): Future_Boolean
Removes a gps marker.

Update(): void
update(): void
Does not need to be called manually.

Future_...

Finished(): bool
finished(): bool
Returns true if a result exists, false otherwise.

Result(): ...
result(): ...
Returns the delayed result, if present. If not present, an exception is thrown. Before this method is called, it should be checked with Finished whether a result is available or not.


GPSInterface - Souce

sealed class GPSInterface { private static readonly string Version = "0"; private readonly IMyTerminalBlock Me; public GPSInterface(IMyTerminalBlock me) { Me = me; Update(); } public IMyTerminalBlock GetInterfaceBlock() => Me; public Future_Boolean IsActive() { PreCheck(); Me.CustomData += string.Format("\r\nActive?"); return new Future_Boolean(Me); } // [Obsolete("Use Update")] public void update() => Update(); public void Update() => Me.CustomData = "[Gps-Scripting:IN]Version:" + Version; private void PreCheck() { if (!Me.CustomData.StartsWith("[Gps-Scripting:IN]")) { Update(); } } // [Obsolete("Use AddGps")] public Future_Integer AddLocalGps(string name, Vector3D position, string description = "", bool persistent = false, bool showOnHud = true) => AddGps(name, position, description, persistent, showOnHud); public Future_Integer AddGps(string name, Vector3D position, string description = "", bool persistent = false, bool showOnHud = true) { PreCheck(); Me.CustomData += string.Format("\r\nAdd:{0}:{1}:{2}:{3}:{4}:{5}:{6}", name, description, position.X, position.Y, position.Z, persistent ? "Y" : "N", showOnHud ? "Y" : "N", -1); return new Future_Integer(Me); } public Future_Integer EditGps(int gpsHash, Vector3D position) { PreCheck(); Me.CustomData += string.Format("\r\nEdit:{0}:{1}:{2}:{3}", gpsHash, position.X, position.Y, position.Z); return new Future_Integer(Me); } public Future_List List() { PreCheck(); Me.CustomData += string.Format("\r\nList"); return new Future_List(Me); } // [Obsolete("Use RemoveGps")] public Future_Boolean RemoveLocalGps(int gpsHash) => RemoveGps(gpsHash); public Future_Boolean RemoveGps(int gpsHash) { PreCheck(); Me.CustomData += string.Format("\r\nRemove:{0}", gpsHash); return new Future_Boolean(Me); } public Future_Boolean Clear() { PreCheck(); Me.CustomData += string.Format("\r\nClear"); return new Future_Boolean(Me); } public abstract class Future < T > { protected int line; protected IMyTerminalBlock b; protected string[] cache; public Future(IMyTerminalBlock b) { line = b.CustomData.Split(new string[] { "\r\n" }, StringSplitOptions.None).Length - 1; this.b = b; } public bool Finished() { if (cache == null || cache.Length <= line) { cache = b.CustomData.Split(new string[] { "\r\n" }, StringSplitOptions.None); } return cache[0].StartsWith("[Gps-Scripting:OUT]") && cache.Length > line; } // [Obsolete("Use Finished")] public bool finished() => Finished(); public T Result() { if (!Finished()) { throw new Exception("Future not finished"); } return Result0(); } // [Obsolete("Use Result")] public T result() => Result(); protected abstract T Result0(); } public sealed class Future_Boolean: Future < bool > { public Future_Boolean(IMyTerminalBlock b): base(b) {} protected override bool Result0() => cache[line].Equals("Ok"); } public sealed class Future_Integer: Future < int > { public Future_Integer(IMyTerminalBlock b): base(b) {} protected override int Result0() { try { return int.Parse(cache[line]); } catch (Exception) { return -1; } } } public sealed class Future_List: Future < List < GPS_Entry >> { public Future_List(IMyTerminalBlock b): base(b) {} protected override List < GPS_Entry > Result0() => cache[line].Split(new string[] { "::" }, StringSplitOptions.None).Where(e => e.Length > 0).Select(i => new GPS_Entry(i)).ToList(); } public sealed class GPS_Entry { public readonly string Name; public readonly double X; public readonly double Y; public readonly double Z; public GPS_Entry(string item) { string[] items = item.Split(new char[] { ':' }).Select(e => e.Trim()).ToArray(); Name = items[0]; X = double.Parse(items[1]); Y = double.Parse(items[2]); Z = double.Parse(items[3]); } } }
3 Comments
woostyboy 31 Jan, 2018 @ 12:50pm 
Mind....blown... Sadly I don't understand scripting :( but thanks anyway.
Ikarus_Sol_314  [author] 31 Jan, 2018 @ 11:40am 
Unfortunately not. The script adds a gps marker at the pb's postition and removes it 100 ticks (~1 second) later to add a new one. That means very 100 ticks we get a new gps marker. If you add the gps marker to the remote control's waypoints it will fly your ship to your old carrier position (where it was when the gps marker was added).

You should use the IMyRemoteControl.AddWaypoint(Vector3D coords,string name) method (combined with a camera to detect it) to follow your carrier and successfully land on it.
woostyboy 31 Jan, 2018 @ 10:55am 
Is this the answer to my dreams!? Can I put this in a block on a moving carrier and auto land a fighter on it?