Advertisement
Guest User

Untitled

a guest
Nov 20th, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.82 KB | None | 0 0
  1. --@name Colonial Airlock System|V2
  2. --@author Avorius
  3. --@shared
  4. --@class processor
  5.  
  6. if SERVER then
  7.  
  8. function CASV2(...)
  9. printColor(Color(216,38,57), "[CAS:V2]: ", Color(255,255,255), ...)
  10. end
  11.  
  12. CASV2("Initialisation for the Colonial Airlock System|V2 will start in T-Minus 5 Seconds.")
  13.  
  14. StartupPercent = 0
  15. StartupComplete = false
  16.  
  17. Lockdown = false
  18.  
  19. function startupSequence( )
  20.  
  21. wire.createInputs({"OuterAirlock","InnerAirlock","Bulkhead","OuterCycleButton","InnerCycleButton","BulkheadButton"},{"wirelink","wirelink","wirelink","normal","normal","normal"})
  22.  
  23. wire.createOutputs({"SealIndicator"},{"vector"})
  24.  
  25. wire.ports.SealIndicator = Vector(255,95,0)
  26.  
  27. timer.create("startupSequence" , 1, 5, function()
  28. CASV2("Initialising Colonial Airlock System|V2... "..StartupPercent.."%")
  29. StartupPercent = StartupPercent + 25
  30. if timer.repsLeft("startupSequence") == 1 then
  31. timer.simple(2,function()
  32. --Definition Variables for ease of use
  33. if IsValid(wire.ports.OuterAirlock) and
  34. IsValid(wire.ports.InnerAirlock) and
  35. IsValid(wire.ports.Bulkhead) and
  36. wire.ports.OuterCycleButton ~= nil and
  37. wire.ports.InnerCycleButton ~= nil and
  38. wire.ports.BulkheadButton ~= nil then
  39. OAIR = wire.ports.OuterAirlock
  40. IAIR = wire.ports.InnerAirlock
  41. BULK = wire.ports.Bulkhead
  42.  
  43. OUTB = wire.ports.OuterCycleButton
  44. INNB = wire.ports.InnerCycleButton
  45. BULB = wire.ports.BulkheadButton
  46.  
  47. if BULK["Opened"] == 1 then
  48. BULK["Toggle"] = 1
  49. end
  50. if IAIR["Opened_1"] == 1 then
  51. IAIR["Open_1"] = 0
  52. IAIR["Lock_1"] = 1
  53. end
  54. if OAIR["Opened_1"] == 0 then
  55. OAIR["Locked_1"] = 0
  56. OAIR["Open_1"] = 1
  57. end
  58.  
  59. StartupComplete = true
  60. wire.ports.SealIndicator = Vector(255,0,0)
  61. CASV2("Colonial Airlock System|V2 initialisation complete!")
  62. timer.remove("startupSequence")
  63. else
  64. CASV2("Colonial Airlock System|V2 initialisation failed. Please wire up all the components and reload the chip.")
  65. end
  66. end)
  67. end
  68. end)
  69. end
  70.  
  71. hook.add( "input", "inputHook", function( i, v )
  72. if StartupComplete then
  73. if i == "BulkheadButton" then
  74. if v == 1 then
  75. if BULK["Opened"] == 1 then
  76. Lockdown = true
  77. CASV2("Lockdown initiated!")
  78. BULK["Toggle"] = 1
  79. wire.ports.SealIndicator = Vector(255,0,0)
  80. IAIR["Lock_1"] = 1
  81. IAIR["Open_1"] = 0
  82. OAIR["Lock_1"] = 1
  83. else
  84. Lockdown = false
  85. CASV2("Lockdown lifted!")
  86. BULK["Toggle"] = 1
  87. wire.ports.SealIndicator = Vector(0,255,0)
  88. IAIR["Lock_1"] = 0
  89. IAIR["Open_1"] = 1
  90. OAIR["Lock_1"] = 0
  91. end
  92. end
  93. elseif i == "InnerCycleButton" then --Always use elseif for functions like these, it can only possibly be one no point in 3 separate checks
  94. if v == 1 then
  95. if Lockdown == false then
  96. if IAIR["Opened_1"] == 0 then
  97. CASV2("Cycling the airlock!")
  98. OAIR["Lock_1"] = 1
  99. timer.simple(3, function()
  100. IAIR["Lock_1"] = 0
  101. IAIR["Open_1"] = 1
  102. end)
  103. else
  104. CASV2("Cycling the airlock!")
  105. IAIR["Lock_1"] = 1
  106. timer.simple(3, function()
  107. OAIR["Lock_1"] = 0
  108. OAIR["Open_1"] = 1
  109. end)
  110. end
  111. else
  112. CASV2("Cannot comply! Lockdown has been initiated!")
  113. end
  114. end
  115. elseif i == "OuterCycleButton" then
  116. if Lockdown == false then
  117. if v == 1 then
  118. if IAIR["Opened_1"] == 0 then
  119. CASV2("Cycling the airlock!")
  120. OAIR["Lock_1"] = 1
  121. timer.simple(3, function()
  122. IAIR["Lock_1"] = 0
  123. IAIR["Open_1"] = 1
  124. end)
  125. else
  126. CASV2("Cycling the airlock!")
  127. IAIR["Lock_1"] = 1
  128. timer.simple(3, function()
  129. OAIR["Lock_1"] = 0
  130. OAIR["Open_1"] = 1
  131. end)
  132. end
  133. end
  134. else
  135. CASV2("Cannot comply! Lockdown has been initated!")
  136. end
  137. end
  138. end
  139. end)
  140.  
  141. timer.simple(5,function()
  142. startupSequence()
  143. end)
  144. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement