Advertisement
Guest User

Door

a guest
Nov 9th, 2012
490
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.25 KB | None | 0 0
  1. -- Configuration
  2. -- Strings
  3. local sBypasspw = "lastmyth"
  4. local sDoorpw = "derp"
  5. local sRedstoneSideClose = "back"
  6. local sRedstoneSideOpen = "bottom"
  7. local sName = "The Sorting Facility"
  8. local wp = "print"
  9.  
  10. -- Do not edit from here
  11.  
  12. -- [[ Menu, clear print, and welcome functions ]] --
  13.  
  14. local function menu(...)
  15. local sel = 1
  16. local list = {...}
  17. local offX,offY = term.getCursorPos()
  18. local curX,curY = term.getCursorPos()
  19. while true do
  20. if sel > #list then sel = 1 end
  21. if sel < 1 then sel = #list end
  22. for i = 1,#list do
  23. term.setCursorPos(offX,offY+i-1)
  24. if sel == i then
  25. print("["..list[i].."]") -- very customisible example print(">"..list[i])
  26. else
  27. print(" "..list[i].." ") -- very customisible
  28. end
  29. end
  30. while true do
  31. local e,e1,e2,e3,e4,e5 = os.pullEvent()
  32. if e == "key" then
  33. if e1 == 200 then -- up key
  34. sel = sel-1
  35. break
  36. end
  37. if e1 == 208 then -- down key
  38. sel = sel+1
  39. break
  40. end
  41. if e1 == 28 then
  42. term.setCursorPos(curX,curY)
  43. return list[sel],sel
  44. end
  45. end
  46. end
  47. end
  48. end
  49.  
  50. function clearPrint(string, x, y)
  51. if not x or x < 0 then x = 1 end
  52. if not y or y < 0 then y = 1 end
  53. term.clear()
  54. term.setCursorPos(x,y)
  55. print(string)
  56. end
  57.  
  58. function Welcome(string)
  59. clearPrint("+-----------------------------------------------+")
  60. print("+-- Welcome to "..sName.." --+")
  61. print("+-----------------------------------------------+\n")
  62. print(string)
  63. end
  64.  
  65. -- [[ Open and Close functions ]] --
  66.  
  67. function Open()
  68. Welcome("Opening doors...")
  69. for i = 1,5 do
  70. rs.setOutput(sRedstoneSideOpen,true)
  71. sleep(.425)
  72. rs.setOutput(sRedstoneSideOpen,false)
  73. sleep(.425)
  74. end
  75. Welcome("Doors have been opened!")
  76. sleep(1)
  77. begin()
  78. end
  79.  
  80. function Close()
  81. update = true
  82. Welcome("Closing garage doors...")
  83. sleep(1.5)
  84. Welcome("Closing doors...")
  85. for i = 1,5 do
  86. rs.setOutput(sRedstoneSideClose,true)
  87. sleep(.425)
  88. rs.setOutput(sRedstoneSideClose,false)
  89. sleep(.425)
  90. end
  91. Welcome("Doors have been closed!")
  92. sleep(1)
  93. begin()
  94. end
  95.  
  96. function Exit()
  97. Welcome("Exiting...")
  98. sleep(1.5)
  99. end
  100.  
  101. -- [[Check Password]] --
  102.  
  103. function checkPW(PW)
  104. if PW == sDoorpw then
  105. Welcome("Password correct!")
  106. sleep(1.5)
  107. Welcome("Choose an option:")
  108. local selection = menu(
  109. " Open ",
  110. " Close ",
  111. " Exit ")
  112. if selection == " Open " then
  113. Open()
  114. elseif selection == " Close " then
  115. Close()
  116. elseif selection == " Exit " then
  117. Exit()
  118. end
  119. elseif PW == sBypasspw then
  120. Open()
  121. else
  122. Welcome("Password invalid.")
  123. sleep(1.5)
  124. end
  125. end
  126.  
  127. function begin()
  128. Welcome("Enter password:")
  129. write(" > ")
  130. checkPW(read("*"))
  131. end
  132.  
  133. begin()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement