drabont

Space Engineers - Symple Hydrogen Trade

Apr 17th, 2021
792
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Space Engineers - Symple Hydrogen Trade scrips v0.1 by swagman //instruction: https://youtu.be/uOwzDUgW4z4
  2. public Program() { Runtime.UpdateFrequency = UpdateFrequency.Update10; }
  3.  
  4. float LitersPerSC = 7; //price
  5. double LitersOld;
  6.  
  7. public void Main(string arg) {/*mon init*/var m = Me.GetSurface(0); m.ContentType = ContentType.TEXT_AND_IMAGE; m.FontSize = 26.4f/15; m.TextPadding = 0;m.Font = "Monospace"; m.FontColor = Color.Gray; m.BackgroundColor = new Color(0,0,7);
  8.  
  9.   var tn = GridTerminalSystem.GetBlockWithName("!Tank") as IMyGasTank;
  10.   var sc = GridTerminalSystem.GetBlockWithName("!Connector") as IMyShipConnector;
  11.  
  12.   MyItemType Сurrency = new MyItemType("MyObjectBuilder_PhysicalObject", "SpaceCredit");
  13.  
  14.   var LitersCurr = tn.Capacity * tn.FilledRatio;
  15.   m.WriteText($"=HYDRO FUELING=\nHAVE:{LitersCurr:F0} L\n  BY:{LitersPerSC} L/SC\n");
  16.  
  17.   if (sc.Status==MyShipConnectorStatus.Connected) {
  18.     var oi = sc.OtherConnector.GetInventory();
  19.     var cash = oi.GetItemAt(0);
  20.     var money = cash?.Type==Сurrency ? cash?.Amount : 0;
  21.     if (money==0) sc.Disconnect(); else {
  22.       var diff = LitersOld - LitersCurr;
  23.       int pay = (int)Math.Truncate(diff / LitersPerSC);
  24.       sc.GetInventory().TransferItemFrom(oi, 0, null, true, pay );
  25.       LitersOld = LitersCurr + (diff - pay * LitersPerSC);
  26.     };
  27.     m.WriteText($"CASH:{money} SC\n  OR:{money*LitersPerSC} L",true);
  28.   } else LitersOld = LitersCurr;
  29. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×