Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Auto Door Closing Script [EXPERIMENTAL VERSION]
- //
- //--------------------------------SETUP--------------------------------
- //Ignores all doors with the name "Airtight Hangar Door"
- //Make a timer and set it to run this script and trigger itself instantly
- //--------------------------Adding Exceptions--------------------------
- //Simply add the tag "[Excluded]" without the quotes to exclude a door
- //---------------------Airlock Functionality---------------------------
- //Script can support 4 airlock doors
- //Airlock names should include the following:
- // * Stbd Airlock 1 and Stbd Airlock 2 , Port Airlock 1 and Port Airlock 2
- // * Port doors and Stbd doors operate independently from each other
- // * If Airlock 1 is open Airlock 2 will not open until its counterpart is closed
- //
- //This Code is experimental in the sense that it runs continuously. If the doors
- //do NOT stay open for the predicted [3] seconds, please contact me so I can try
- //and fix it :D
- // -Whiplash141
- //-------------------------Code Start----------------------------------
- //Our lists
- Dictionary<IMyTerminalBlock, int> dict = new Dictionary<IMyTerminalBlock, int>();
- List<IMyTerminalBlock> hangarDoors = new List<IMyTerminalBlock>();
- List<IMyTerminalBlock> excludedDoors = new List <IMyTerminalBlock>();
- const int MAX_SECONDS = 180; //1 second = 60, adjust as u see fit
- void Main() {
- List<IMyTerminalBlock> blocks = new List<IMyTerminalBlock>();
- GridTerminalSystem.GetBlocksOfType<IMyDoor>(blocks);
- GridTerminalSystem.SearchBlocksOfName("Airtight Hangar Door",hangarDoors);
- //Here is the exception part
- GridTerminalSystem.SearchBlocksOfName("[Excluded]",excludedDoors); //change [Excluded] to what u want
- for(int i = 0; i < blocks.Count; i++) {
- var door = blocks[i] as IMyDoor;
- //I have no clue if this works
- for (int j = 0; j < hangarDoors.Count; j++ ){
- IMyDoor hangarDoor = hangarDoors[j] as IMyDoor;
- dict.Remove(hangarDoor);
- }
- for(int k = 0; k < excludedDoors.Count; k++){
- IMyDoor excludedDoor = excludedDoors[k] as IMyDoor;
- dict.Remove(excludedDoor);
- }
- if(dict.ContainsKey(door)) {
- if(!door.Open) {
- dict.Remove(door);
- } else {
- int doorCount;
- dict.TryGetValue(door, out doorCount);
- dict.Remove(door);
- if(doorCount++ < MAX_SECONDS)
- dict.Add(door, doorCount);
- else
- door.GetActionWithName("Open_Off").Apply(door);
- }
- } else {
- if(door.Open)
- dict.Add(door,0);
- }
- }
- //----------End of auto door close part of script---------------
- //----------Start Airlock Script--------------------------------
- //Make Airlock Lists
- List<IMyTerminalBlock> doorList1 = new List<IMyTerminalBlock>();
- List<IMyTerminalBlock> doorList2 = new List<IMyTerminalBlock>();
- List<IMyTerminalBlock> doorList3 = new List<IMyTerminalBlock>();
- List<IMyTerminalBlock> doorList4 = new List<IMyTerminalBlock>();
- GridTerminalSystem.SearchBlocksOfName("Port Airlock 1",doorList1);
- GridTerminalSystem.SearchBlocksOfName("Port Airlock 2",doorList2);
- GridTerminalSystem.SearchBlocksOfName("Stbd Airlock 1",doorList3);
- GridTerminalSystem.SearchBlocksOfName("Stbd Airlock 2",doorList4);
- //Airlock Check 1 (Port)
- if(doorList1.Count != 0 && doorList2.Count != 0)
- {
- for(int k = 0; k < doorList1.Count; k++)
- {
- IMyDoor door1 = doorList1[k] as IMyDoor;
- for(int j = 0; j < doorList2.Count; j++)
- {
- IMyDoor door2 = doorList2[j] as IMyDoor;
- if(door1.Open)
- {
- door2.GetActionWithName("Open_Off").Apply(door2);
- door2.GetActionWithName("OnOff_Off").Apply(door2);
- }
- else
- {
- door2.GetActionWithName("OnOff_On").Apply(door2);
- }
- if(door2.Open)
- {
- door1.GetActionWithName("Open_Off").Apply(door1);
- door1.GetActionWithName("OnOff_Off").Apply(door1);
- }
- else
- {
- door1.GetActionWithName("OnOff_On").Apply(door1);
- }
- }
- }
- }
- //Airlock Check 2(Stbd)
- if(doorList3.Count != 0 && doorList4.Count != 0)
- {
- for(int k = 0; k < doorList3.Count; k++){
- IMyDoor door3 = doorList3[k] as IMyDoor;
- for(int j = 0; j < doorList4.Count; j++){
- IMyDoor door4 = doorList4[j] as IMyDoor;
- if(door3.Open)
- {
- door4.GetActionWithName("Open_Off").Apply(door4);
- door4.GetActionWithName("OnOff_Off").Apply(door4);
- }
- else
- {
- door4.GetActionWithName("OnOff_On").Apply(door4);
- }
- if(door4.Open)
- {
- door3.GetActionWithName("Open_Off").Apply(door3);
- door3.GetActionWithName("OnOff_Off").Apply(door3);
- }
- else
- {
- door3.GetActionWithName("OnOff_On").Apply(door3);
- }
- }
- }
- }
- } //the void main bracket
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement