Space Engineers

Space Engineers

135 ratings
Easy Throttle Control & Max speed Script
2
3
   
Award
Favorite
Favorited
Unfavorite
File Size
Posted
Updated
499.737 KB
Aug 10, 2020 @ 8:44pm
Jan 20, 2024 @ 7:31pm
18 Change Notes ( view )

Subscribe to download
Easy Throttle Control & Max speed Script

Description
A Simple Script that simulates a throttle
Finally, if you want to fly at 50 m/s you just hold w (or your forward button) until you reach 50 m/s and let go. The script will keep you going forward at 50 m/s!
To stop simply press s (or your backward button) and you will stop like normal.


Multiple flight modes!
You can now choose between three flight modes
To change flight modes double press Forward (default W) of Backward (Default S)
More info in Flight modes located below!

//////////////////////////////////////////////////////////////////////////////////////////
Setup
//////////////////////////////////////////////////////////////////////////////////////////
Place a program block on the ship of your choosing.
Make sure you add !main to the main cockpit or/and remote control block.
If you want an LCD to show some stats add !Throttle to the name, multiple displays are supported.
To change the LCD in the cockpit that displays the throttle control info change LCD_INDEX where 0 is the first LCD in the cockpits LCD list. You can also disable the cockpit LCD by changing ENABLE_COCKPIT_LCD to false.

//////////////////////////////////////////////////////////////////////////////////////////
Settings
//////////////////////////////////////////////////////////////////////////////////////////
Eco Mode
Eco Mode will prioritize using non hydrogen thrusters. Helpful to reduce fuel consumption for ships with both hydrogen and ion/atmospheric thrusters.
Eco mode can be toggled using eco as a command argument.
Please note: eco mode only works on Vanilla hydrogen thrusters and may not work with modded thrusters. Modded thrusters will be controlled as if they where a atmospheric or ion thruster.
If you want to disable the double tap feature and use next and last to as arguments to change modes then set DOUBLE_TAP_DELAY to 0, should look like:
const int DOUBLE_TAP_DELAY = 0;

Exit cockpit behavior
SET_MODE_0_ON_EXIT
When true the script will return to normal mode when the player exits the cockpit.
When false the script will continue to try and maintain its speed.

Thruster Groups
By default the script will use all thrusters, however if you want to use merge blocks or if you only want some thrusters to be controlled by the script you can create a group of thrusters. Create the group with a unique name, go into the script and change the GROUP_NAME setting. For example if you name your group !Throttle then you would change GROUP_NAME line to this
string GROUP_NAME = "!Throttle";

Subgrids
If you want to allow the script to see grids connected through a rotor then set ENABLE_SUB_GRID_THRUSTERS to true. Note be careful with this as the script will control thrusters on all grids connected via rotors. When this mode is enabled you will first have to disconnect all connectors.


//////////////////////////////////////////////////////////////////////////////////////////
How to set a speed
//////////////////////////////////////////////////////////////////////////////////////////
Method 1: Hold forward until you reach your desired speed.
Release forward. The ship will now maintain that speed. To stop simply press the revers key. The ship will go back to normal operation, unless you are in another mode. See “Flight modes" for more on how flight modes effect flight behavior.

Method 2: Run the script with a value in the argument between 1 and the max speed of your world. To stop simply press the revers key. The ship will go back to normal operation.

//////////////////////////////////////////////////////////////////////////////////////////
Flight modes
//////////////////////////////////////////////////////////////////////////////////////////
Flight modes are a way to change how the script effects your ship. Each mode will affect how the ship operates and handles.
The flight modes are in a hierarchy list to allow multiple modes to be accessible with only two actions.
The list is as follows with Cruise being the default
Normal
Cruise
Cruise+
Decoupled (Disabled by default, turn it on in the settings)
Governor

//////////////////////////////////////////////////////////////////////////////////////////
Mode descriptions
//////////////////////////////////////////////////////////////////////////////////////////
Normal: This mode disables the speed control so you can fly like it was off. You can still change modes however.

Cruise: This is the default mode. When you hold forward the ship will accelerate, when you release forward the ship will set your current speed as the target speed and it will do everything it can to maintain this speed. Pressing backwards will set the target speed to 0 and the ship will operate like normal. This mode lets you quickly switch between cruise control and normal inertia dampener mode (as long as inertia dampeners are on) as pressing backwards will stop the ship in an emergency.

Cruise+: This mode is like cruise however, when backwards is pressed the ship will slow down instead of stopping, it sets your new speed to your current speed just like it would if you held forward. This mode allows you to adjust your speed without the ship trying to stop every time you press backwards. However the problem is that if you need to stop your ship completely have to change the mode first to another mode like “Cruise” or “Normal”.

Decoupled: Decoupled Mode is like cruise+ except that it works in all directions. NOTE: Decoupled mode can be finicky to use as the ship will use the cockpit as the reference point, so if you are flying up and you rotate 90 degrees up so you are now moving forward instead of up, your ship will try to make you fly up again making you stop going forward. Also the speed is additive, so if you then press forward, the ship will now try to make you fly up and forward. Because of this I have disabled this mode by default. However you can still enable it in the script settings.

Governor: This mode is used for ships that need to move slowely but still maintain compleat control. Where in the other modes the script maintains a given speed without holding down any keys, this mode keeps you from exceeding a given speed while holding down a key. This is good for a welder ship as you can fly like normally but once you hit a given speed (Default 5m/s) you will stop accelerating. To change the speed enter max x into the programming blocks argument text box where x is the speed you want then press run, for example to set a max speed of 12m/s you would type max 12. Negative values will invert the controls, so don't use negative values!

There are two ways to change flight modes
Method 1: Double press forward or backwards to move through the flight mode list.
Method 2: Write the flight mode name as an argument, this allows you to change to any flight mode you want regardless of its hierarchy position.


//////////////////////////////////////////////////////////////////////////////////////////
Arguments
//////////////////////////////////////////////////////////////////////////////////////////
"stop" -- stops the script
"next" -- Go to the next flight mode
"last" -- Go to the previous mode
"previous" -- Same as last, Go to the previous mode
"cruise" –- special flight mode where backwards stops the ship and forward sets the speed
"cruise+" -- Special flight mode where backwards slows down but doesn’t stop
"decoupled" -- Cruise+ in any direction. Be careful with this mode!
"governor" -- Governor flight mode where you wont exceed a given speed.
"max number" -- set the max Governor mode speed to number
"number" –- set the target speed to whatever number is set to
"eco" – Toggle Eco mode on/off
"eco on" – Toggle eco mode on
"eco off" – Toggle eco mode off


Use the link below to view the MDK project
https://github.com/Doktor-Doraro/SimpleThrottleControl
131 Comments
Jotaro Feb 8 @ 9:49am 
Most of the time it breaks if there is another programmable block with same script
Jotaro Feb 8 @ 8:16am 
Merge blocks breaks this script that won't work anymore even when recompiling and only says "Enter the main cockpit to initialise thrusters or control the remote control block, there is no LCD with index '1' in the main cockpit, please change LCD_INDEX"
Jotaro Jan 18 @ 5:35am 
Can't get subgrid control to work have another ship through connector
G43 mai waifu Dec 1, 2024 @ 9:23am 
...wait I can't reproduce that in another save.lemme take another look
G43 mai waifu Dec 1, 2024 @ 9:11am 
It has some issue
when ship has a cryo chamber it stops working
Kilo.Four Jul 11, 2024 @ 6:07pm 
Sorry I got it to work. Had to remove the programmable block and start over. I must have messed something up.

Thanks again for making such a cool script.
Kilo.Four Jul 11, 2024 @ 6:03pm 
Super cool script!

I have the same question as R5Dad though. I can get it to work with cockpits but not control seats. Tried adjusting setting to false as you recommended but still doesn't work. I set control seat to main and also tried adding !main to the title. Still nothing.

Really excited to get this to work! Thanks!
Delta Hawk Jun 20, 2024 @ 6:11pm 
How do I add !Throttle to the screen of a programmable block so I can see the throttle information?
Ubermensch Jun 11, 2024 @ 1:54pm 
It's one of the best modes of the game. I'm currently using it without any issues.
DoktorKrove  [author] Jan 20, 2024 @ 7:33pm 
@BeetBurger
I fixed the Governor more now it should no longer accelerate uncontrollably when you fly in more then 1 direction!