Morphik08

Space Engineers Drone Return on empty guns

Jan 3rd, 2017
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.02 KB | None | 0 0
  1. //The name of the remote control to trigger.
  2. const string remoteName = "Remote Control";
  3.  
  4. List<IMyTerminalBlock> guns = new List<IMyTerminalBlock>();  
  5.  
  6. void Main()  
  7. {
  8.     var remote = GridTerminalSystem.GetBlockWithName(remoteName) as IMyRemoteControl;
  9.  
  10.     if (guns.Count == 0)
  11.     {
  12.         GridTerminalSystem.GetBlocksOfType<IMySmallGatlingGun>(guns, b => b.CubeGrid == Me.CubeGrid);
  13.     }
  14.  
  15.     double maxVol = 0.0d;
  16.     double curVol = 0.0d;
  17.     double percentFull;    
  18.  
  19.     for (int i = 0; i < guns.Count; i++)
  20.     {
  21.         var inventory = (guns[i]).GetInventory(0);
  22.          
  23.         curVol += (double)inventory.CurrentVolume;  
  24.         maxVol += (double)inventory.MaxVolume;
  25.     }
  26.  
  27.     percentFull = Math.Round(100 * (curVol / maxVol),2);  
  28.     var log = "Capacity: " + (percentFull / 100).ToString("P2");  
  29.     Echo(log);
  30.  
  31.     if (percentFull == 0)
  32.     {
  33.         remote.ApplyAction("AutoPilot_On");
  34.     }
  35.     else
  36.     {
  37.         remote.ApplyAction("AutoPilot_Off");
  38.     }
  39.    
  40. }
Advertisement
Add Comment
Please, Sign In to add comment