Space Engineers

Space Engineers

1,422 ratings
Whip's Auto Door and Airlock Script
3
2
5
3
   
Award
Favorite
Favorited
Unfavorite
File Size
Posted
Updated
630.981 KB
30 Mar, 2015 @ 5:34pm
12 Sep, 2021 @ 12:01pm
50 Change Notes ( view )

Subscribe to download
Whip's Auto Door and Airlock Script

In 1 collection by Whiplash141
Whip's Scripts
22 items
Description

  Description
"Sure, I could turn around and close the door like a civilized man.
Or I could let a robot do it for me... like a modern man.
"
    - Acarii on the virtues of automatic doors

This script will close any door once it has been fully open for over 3 seconds (10 seconds for hangar doors). The duration that a door is allowed to be open is independent of the status of any other doors. This is to say that if I open one door at a certain time then open another door a second later, each door will stay open for 3 seconds, then close. This script also supports an INFINITE amount of simple airlock systems.


  Instructions
  1. Place this script in a programmable block
  2. (Optional) Set up airlock systems
If you don't want/need the airlock functionality, only step (1) is necessary!

Auto Door Closer
The script will fetch ALL doors on the grid and automagically close any
door that has been open for a set number of seconds. Doors can also be excluded from
this feature.

Changing the Auto-Close Interval
You can change the auto close interval one of two ways:
  • Globally by changing the "auto close time" in the Custom Data of the Programmable Block
  • Per door by changing "Custom auto close time (s)" and setting "Use default auto close time" to false in the Custom Data of a Door.

Excluding Doors:
Add the tag "Excluded" anywhere in the door's name to exclude it from auto closing. Hangar doors are excluded from auto closing by default, but you can change that in the Custom Data of this programmable block.


Airlocks
This script supports the optional feature of airlock systems. Airlock systems are composed of AT LEAST one Interior Door AND one Exterior Door. The airlock status lights and sound blocks do not affect the functionality of the doors so if you don't have space for them, don't fret :)

Naming:
  • Interior doors should be named like so: "[Prefix] Airlock Interior"
  • Exterior doors should be named like so: "[Prefix] Airlock Exterior"
  • (Optional) Airlock status lights should be named like so: "[Prefix] Airlock Light"
  • (Optional) Airlock Sound Block should be named like so: "[Prefix] Airlock Sound"
  • The "[Prefix]" is the unique name that you group your airlock doors by

    Example Names:
    • "Main Airlock Interior" and "Main Airlock Exterior"
    • "[Main] Airlock Interior" and "[Main] Airlock Exterior"
    • "Potato Airlock Interior" and "Potato Airlock Exterior"
    • "1337 Airlock Interior" and "1337 Airlock Exterior"
Rules:
  • An airlock system is composed of at least one Interior Door and one Exterior Door. You can have more than one of each type of door. If you do not have one or more Interior and Exterior doors in your airlock system, that particular system will be ignored.
  • Prefixes are case insensitive and spaces are ignored
  • Doors with the same prefix are linked together in an airlock system
  • You do not need an airlock light for the doors to function properly
  • For each airlock system, if an Interior Door is opened, all Exterior Doors are locked and vice versa
  • Each airlock system operates independently of others


  Custom Data Configuration
I've rewritten this code (yet again) to support Custom Data configuration. This means that you do not need to touch any values inside of the code.

Programmable Block Config
In the Custom Data of the programmable block, you can change the global default auto close intervals as well as any and all of the name tags used by this script.
[Auto Door and Airlock - General Config] Enable automatic door closing=true Enable airlock system=true Ignore all hangar doors=true Default regular door auto close time (s)=3 Default hangar door auto close time (s)=10 Auto door exclusion name tag=Excluded Interior airlock door name tag=Airlock Interior Exterior airlock door name tag=Airlock Exterior Airlock light name tag=Airlock Light Airlock sound block name tag=Airlock Sound

Per Door Config
By popular request, if you want to set auto close intervals per door, you can do so in the Custom Data of a door.
[Auto Door and Airlock - Door Config] Use default auto close time=true ; To use a custom auto close time, set "Use default auto close time" to false Custom auto close time (s)=3

Airlock Light Config
Because hardcoding stuff is mega lame, I've also added configuration settings in the Custom Data of light blocks that are being used as airlock indicator lights.
[Auto Door and Airlock - Light Config] Turn on when airlock is open=true Airlock open - Color (R,G,B)=255, 40, 40 Airlock open - Blink interval (seconds)=0.8 Airlock open - Blink length (%)=50 Turn on when airlock is closed=true Airlock closed - Color (R,G,B)=80, 160, 255 Airlock closed - Blink interval (seconds)=0.8 Airlock closed - Blink length (%)=100


  Author's Notes
This script has been rewritten (on 2021/02/22) to support Custom Data configuration. The script is still very performance friendly, and this should make configuring stuff much cleaner since you no longer need to edit variables in the code.

This is/was my first script, I hope y'all enjoy! :)

Thanks to LordTylus for the script in his Self-Maintaining Survival Ship that I initially based the logic of the auto door closing on. It was.one of my first exposures to C# and partially responsible for piquing my interest in programming :)

If you have any questions, comments, or concerns, feel free to leave a comment.

- Whiplash141 :)

(Do not reupload without permission, not even to mod.io)
Popular Discussions View All (8)
111
14 Apr, 2024 @ 10:37am
PINNED: Bug Reports
Whiplash141
26
19 Sep, 2024 @ 8:50pm
Feature Requests
CTH2004
7
14 May, 2021 @ 9:40pm
How can I setup an Airvent to work with this?
rottielover
570 Comments
aTruckgril Beverly ✿ 15 May @ 11:22pm 
@blurrymetal53 Hey, I get where you're coming from. Adding new functionality can be a bit tricky when you're still learning, but it's great that you're diving into it.

For detecting when the airlock is open and turning the LCD on or off, here’s a basic approach you can follow:

Check the status of the airlock door. You’ll usually want to get its Status property and see if it’s DoorStatus.Open.

Use an if statement to detect if it’s open or closed.

Then toggle the LCD on or off using the ShowPublicTextOnScreen() or by enabling/disabling the surface.

Let me know if that helps at all :)
BlurryMetal53 14 May @ 8:27pm 
I'm trying to add functionality to the script to turn on/off an LCD when it detects the airlock open, but can't for the life of me figure it out as I have no real experience coding. Anyway you can give me some tips for it?
Commander_Idiot 1 Mar @ 5:06am 
Nvm, apologies for my stupid question. I didn't read far enough.
Commander_Idiot 1 Mar @ 4:56am 
Will this work on an airlock with three doors? One leading to the interior and two to the exterior? If it does work, is it just following the same steps with the names?
Elafis 7 Nov, 2024 @ 12:21pm 
it is possible make some update if ship is in atmosfer? outter door open immidiately without depressure becouse ouside is pressure? Or for double hangar door possibile open both doors together if both side is (de)pressure? Thank you a lot :)
NekoJess 6 Nov, 2024 @ 5:45am 
[Rose]Noot Try checking the code again.
Adolf Rizzler 6 Nov, 2024 @ 3:13am 
Im not sure what im doing wrong, I cant get the airlock part to work, I have two connected doors named [Garage] Airlock Exterior and [Garage] Airlock Interior, however the boths doors can be opened without the other being closed. Any suggestions?
Whiplash141  [author] 22 Oct, 2024 @ 9:37pm 
This script finds every door not name tagged with "Ignore". It does not currently use groups.
PrinceSporus 22 Oct, 2024 @ 8:19pm 
Does it work with groups or do I need to rename each individual block?
Whiplash141  [author] 28 Sep, 2024 @ 5:28pm 
Yep, set "Ignore all hangar doors" in the program block custom data to false