Space Engineers

Space Engineers

1,335 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 @ 10:37am
PINNED: Bug Reports
Whiplash141
24
10 Jun @ 10:35pm
Feature Requests
CTH2004
7
14 May, 2021 @ 9:40pm
How can I setup an Airvent to work with this?
rottielover
551 Comments
Whiplash141  [author] 14 Jul @ 3:17pm 
I do see one potential issue here: Your airlock doors are named in the pattern of "Sliding Hatch Door - Airlock Exterior". This means that the code detects the airlock prefix as "Sliding Hatch Door -". Anything before the airlock suffixes is treated as the name tag.
Whiplash141  [author] 14 Jul @ 3:15pm 
I see no blocks on this ship with the name tag "... Airlock Light" or "... Airlock Sound". Is this the right blueprint?
Sean W. 14 Jul @ 1:05pm 
Here is a blueprint for you to look over.
https://steamproxy.net/sharedfiles/filedetails/?id=3280647837
Whiplash141  [author] 14 Jul @ 2:56am 
Have a blueprint i can look at?
Sean W. 14 Jul @ 2:18am 
Yes
Whiplash141  [author] 14 Jul @ 12:52am 
You need the prefix on those block names as well. Do you have the same airlock prefix on all the airlock doors, the light, and the sound block?
Sean W. 13 Jul @ 10:26pm 
Yes, I made sure to check all ownership. And I used the exact names in the script "Airlock Light" and "Airlock Sound" but it's still not working.
Whiplash141  [author] 13 Jul @ 8:00pm 
give me an example of the names you are using. Also, have you checked ownership of all blocks?
Sean W. 13 Jul @ 1:26pm 
I use this script a lot. But there is something wrong when I try to use it for lights and sound blocks. For some reason, the script isn't recognizing the lights and sound blocks even when I name them exactly how the script tells me to.
Whiplash141  [author] 31 May @ 4:31pm 
This script does not control airvents at all. It simply prevents you from spacing all of your oxygen out of a simple airlock. If you want to preserve air, simply set the airvent in your airlock to always depressurize.