Merlin of Mines - Space Engineers

A set of useful scripts for aspiring Space Engineers!

View on GitHub

Cockpit Block Handler

This BlockHandler can support any block which allows you to control ships. This includes cockpits, control seats, control stations, and even cryo chambers. It can also be used to interact with Remote Control objects, though you should consider using the Remote Control Handler instead, as Remote Control inherits all of this BlockHandlers properties and also has some more properties you can modify.

This handler enables you to listen for user input, which has all kinds of potential for things like factories, cranes, drill arms, manned turrets, tanks…

This Block Handler will only briefly touch on handling user input. For much more information, see Handling User Input

Default Primitive Properties:

Default Directional Properties

“Enabled” Property

Gets/Sets whether the given cockpit(s) are considered the Main Cockpit (meaning can control the ship).

#Enable Block
enable "My Cockpit"
set "My Cockpit" to enabled
turn on "My Cockpit"

#Disable Block
disable "My Cockpit"
set "My Cockpit" to disabled
turn off "My Cockpit"

“Power” Property

Effectively the same as the Enabled property.

#Turn on
turn on power to "My Cockpit"
power on "My Cockpit"

#Turn off
turn off power to "My Cockpit"
power off "My Cockpit"

“Override” Property

Gets/Sets whether the dampeners are currently on (meaning overriding)

turn on "My Cockpit" dampeners
set "My Cockpit" overrides to true
override "My Cockpit"

"My Cockpit" dampeners off

“Occupied” Property

Returns whether the Cockpit is currently occupied.

Print "Occupied: " + "My Cockpit" is occupied
Print "In Use: " + "My Cockpit" is in use
Print "Controlled: " + "My Cockpit" is being controlled

“Auto” Property

Identical to Override property. Gets/Sets whether the dampeners are currently on.

set "My Cockpit" to auto
#My personal favorite
tell "My Cockpit" to cooperate
if "My Cockpit" is cooperating
disable "My Cockpit"
Print "Time to chill out and enjoy the ride"

“Lock” Property

Gets/Sets the Handbrake. This is only useful for Rovers, specifically when wheels are present.

#Whoa nelly!
tell "My Cockpit" to brake
set the "Rover Cockpit" handbrake
lock "My Cockpit"

turn off the "Rover Cockpit" handbrake
unlock "My Cockpit"

“Height” Property

Returns the parachute’s current height above the ground, in meters. If not in a gravity well, will return -1.

Print "Cockpit Height: " + "My Cockpit" height

“Altitude” Property

Returns the parachute’s current elevation above sea level, in meters. If not in a gravity well, will return -1.

Print "Cockpit Altitude: " + "My Cockpit" altitude

“Gravity” Property

Gets the current Total Gravity force on the ship as a Vector, in World Coordinates. Note that this includes planet AND artificial gravity combined.

Use the “abs” Operation to get the Gravity Strength.

Print "Gravity: " + "My Cockpit" gravity
Print "Gravity Strength: " + abs "My Cockpit" gravity

“Natural Gravity” Property

Gets the current Natural (i.e., Planet’s) Gravity force on the ship as a Vector, in World Coordinates.

Returns 0:0:0 if not within a planet’s gravity well.

Use the “abs” Operation to get the Natural Gravity Strength.

Print "Natural Gravity: " + "My Cockpit" natural gravity
Print "Natural Gravity Strength: " + abs "My Cockpit" natural gravity

“Artificial Gravity” Property

Gets the current Artificial Gravity force on the ship as a Vector, in World Coordinates.

Returns 0:0:0 if no artifical gravity is currently active.

Use the “abs” Operation to get the Artificial Gravity Strength.

Print "Artificial Gravity: " + "My Cockpit" artificial gravity
Print "Artificial Gravity Strength: " + abs "My Cockpit" artificial gravity

“Weight” Property

Returns the current weight of the ship, in Kg. This includes the weight of the ship and the weight of all onboard cargo.

Print "Ship Total Mass: " + "My Cockpit" mass

“Ratio” Property

Gets the current Oxygen Ratio of the cockpit, as a value from 0 - 1 where 1 = 100%.

Print "Oxygen Ratio: " + "My Cockpit" ratio

“Capacity” Property

Gets the Maximum Oxygen Capacity of the cockpit, in L.

Print "Oxygen Capacity: " + "My Cockpit" capacity

“Velocity” Property

Returns the current velocity of the ship, in m/s. If no direction is specified, returns the ship’s velocity vector directly, in world coordinates.

If a direction is included, then returns the magnitude of the ship’s velocity in the given direction, with respect to the cockpit’s orientation.

Supported Directions:

Print "Ship Velocity: " + "My Cockpit" velocity

if "My Cockpit" upwards velocity > 0
  Print "Drifting upwards"

“Input” Property

If a direction is not included, Returns a Vector (Right:Up:Forwards) representing the magnitude of movement input (values between 0 - 1) from the engineer sitting in the cockpit.

If a direction is included, then returns a value between 0 - 1 representing the user movement input in the specified direction. Specifically, this input is mapped to WASDC + Space for the 6 input directions (not including rotation).

Supported Directions:

See Handling User Input for more information.

if "My Cockpit" input > 0
  Print "Someone is messing with my ship!"

if "My Cockpit" left input > 0
  Print "The boss says move to the left"

“Rotation” Property

If a direction is not included, Returns a Vector (Up:Right:Clockwise) representing the magnitude of rotation input (values between 0 - 1) from the engineer sitting in the cockpit.

If a direction is included, then returns a value between 0 - 1 representing the user roll input in the specified direction. Specifically, this input is mapped to WASDC + Space for the 6 input directions (not including rotation).

Also note that mouse input is considered rotational input (Left/Right/Up/Down), so this property allows you to control rotation based on mouse input.

Supported Directions:

See Handling User Input for more information.

if "My Cockpit" rotation > 0
  Print "Someone is trying to rotate my ship!"

if "My Cockpit" left rotation > 0
  Print "I guess the boss wants to look left"

“Target” Property

Gets/Sets whether the cockpit has Target Locking enabled.

Print "Target Locking Enabled: " + "My Cockpit" targeting is on

turn on "My Cockpit" targeting

Examples

Here’s a full example to print out user input to the Cockpit display:

:main
set myCockpit to "My Cockpit"

async updateDisplay
:updateDisplay
set $myCockpit display text to ""
checkMovement
checkRotation
replay

:checkMovement
if the cockpit upwards input > 0
  setDisplay "Moving Up"
else if the cockpit downwards input > 0
  setDisplay "Moving Down"
else if the cockpit left input > 0
  setDisplay "Moving Left"
else if the cockpit right input > 0
  setDisplay "Moving Right"
else if the cockpit forward input > 0
  setDisplay "Moving Forward"
else if the cockpit backward input > 0
  setDisplay "Moving Backwards"
else
  setDisplay "Movement: " + the cockpit input

:checkRotation
if the cockpit upwards roll > 0
  setDisplay "Rolling Up"
else if the cockpit downwards roll > 0
  setDisplay "Rolling Down"
else if the cockpit left roll > 0
  setDisplay "Rolling Left"
else if the cockpit right roll > 0
  setDisplay "Rolling Right"
else if the cockpit clockwise roll > 0
  setDisplay "Rolling Clockwise"
else if the cockpit counter roll > 0
  setDisplay "Rolling Counter Clockwise"
else
  setDisplay "Roll Input: " + the cockpit roll

:setDisplay myText
increase the $myCockpit display text by myText + "\n"