Emergency Stop on Exiting Cockpit 5/5 (1)

posted in: Control, Navigation, Scripts | 0

This script will turn on all thrusters (in case they’re off) and turn on inertial dampeners.

The best way to use this script is to have a sensor near your cockpit that runs a programmable block when it detects friendly players.

Enjoy!

  1. // This script will turn on all thrusters (in case they are off)
  2. // and toggle inertial dampeners to stop the ship when run.
  3. //
  4. // This script can be used in conjunction with a sensor near the
  5. // cockpit to detect the pilot if he exits the vessel while
  6. // moving. This will have the effect of stopping the vessel
  7. // if the pilot accidentally exits the cockpit while in
  8. // motion.
  9. //
  10. // Alternatively, you can create a timer block to run this script
  11. // on a delay (i.e. 60 seconds). If the timer runs out, the script
  12. // will run and stop the ship. You can set a toolbar key to "Start"
  13. // the timer. That way, the pilot has to press the toolbar key
  14. // before the timer runs out or the ship will stop. This functions
  15. // as a "dead man's switch" to stop the ship in the case the player
  16. // gets disconnected.
  17. void Main() {
  18.  
  19.     // Find all thruster blocks on the ship
  20.     List<IMyTerminalBlock> thrusters = GetThrusters();
  21.    
  22.     // Loop through all thruster blocks and turn them on
  23.     // (in case they are off)
  24.     for (var i = 0; i < thrusters.Count; i++)
  25.     {
  26.         var thruster = thrusters&#91;i] as IMyThrust;
  27.         if (thruster != null) {
  28.             thruster.GetActionWithName("OnOff_On").Apply(thruster);
  29.         }
  30.     }
  31.    
  32.     // Find all controller blocks (cockpits, flight seats, etc)
  33.     List<IMyTerminalBlock> blocks = new List<IMyTerminalBlock>();
  34.     GridTerminalSystem.GetBlocksOfType<IMyShipController>(blocks);
  35.  
  36.     // Loop through all found controller blocks
  37.     for (var i = 0; i < blocks.Count; i++)
  38.     {
  39.         var controller = blocks&#91;i] as IMyShipController;
  40.        
  41.         // If dampeners are not active, turn them on.
  42.         // Unlike the thrusters above, the dampener control
  43.         // is a toggle, so we have to check if it's active
  44.         // before we toggle it, otherwise, if the dampeners
  45.         // are already on, we would turn them off when
  46.         // toggling
  47.         if ((controller != null) && (!controller.DampenersOverride)) {
  48.             controller.GetActionWithName("DampenersOverride").Apply(controller);
  49.         }
  50.     }
  51.    
  52. }
  53.  
  54. // Helper function to find and return all thruster blocks
  55. List<IMyTerminalBlock> GetThrusters()
  56. {
  57.     List<IMyTerminalBlock> list = new List<IMyTerminalBlock>();
  58.     GridTerminalSystem.GetBlocksOfType<IMyThrust>(list);
  59.     return list;
  60. }

Please rate this post

Leave a Reply