L3nna55

lock

Jul 23rd, 2018
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.09 KB | None | 0 0
  1. --[[
  2. This is a Computercraft Security System, made by
  3. FiMa_Coders. You are free to use the code wherever
  4. you want in your builds, but you are not allowed
  5. change the code in any way, except for the things
  6. that are marked "CHANGABLE".
  7.  
  8. If you want to share this program, you can by routing
  9. people to:
  10. http://turtlescripts.com/project/gjdi5q-Security-Code-Lock
  11. ]]
  12.  
  13. os.pullEvent = os.pullEventRaw
  14. shell.openTab("lock2")
  15. sleep(0.1)
  16. shell.switchTab(2)
  17.  
  18.  
  19. m = peripheral.wrap("back")
  20. m.clear()
  21. m.setTextScale(0.5)
  22. m.setBackgroundColor(colors.black)
  23. m.setTextColor(colors.white)
  24.  
  25. load = fs.open("Config", "r")
  26. code,autoReset,waitTime,redstoneSide = unpack(textutils.unserialize(load.readAll()))
  27. load.close()
  28.  
  29. inp = {}
  30. sPos = 4
  31.  
  32.  
  33. function mGUI()
  34. gui = {
  35. [[ senha pf >:3 ]],
  36. [[ LoopRun ]],
  37. [[ +-----------+ ]],
  38. [[ | | ]],
  39. [[ +---+---+---+ ]],
  40. [[ | 1 | 2 | 3 | ]],
  41. [[ | 4 | 5 | 6 | ]],
  42. [[ | 7 | 8 | 9 | ]],
  43. [[ | X | 0 | > | ]],
  44. [[ +---+---+---+ ]],
  45. }
  46. m.setTextColor(colors.red)
  47. for i = 1,10 do
  48. m.setCursorPos(1,i)
  49. if i == 3 then
  50. m.setTextColor(colors.white)
  51. end
  52. m.write(gui[i])
  53. end
  54. m.setCursorPos(3,9)
  55. m.setBackgroundColor(colors.red)
  56. m.write(" X ")
  57. m.setCursorPos(11,9)
  58. m.setBackgroundColor(colors.lime)
  59. m.write(" > ")
  60. m.setCursorPos(3,4)
  61. m.setBackgroundColor(colors.lightGray)
  62. m.write(" ")
  63. end
  64.  
  65. function open()
  66. if autoReset then
  67. if waitTime == 0 then waitTime = 2 end
  68. sleep(waitTime)
  69. rs.setOutput(redstoneSide,false)
  70. os.reboot()
  71. else
  72. m.setBackgroundColor(colors.black)
  73. m.clear()
  74. m.setTextScale(5)
  75. m.setCursorPos(1,1)
  76. m.write("<")
  77. ev, side, xPos, yPos = os.pullEvent("monitor_touch")
  78. rs.setOutput(redstoneSide,false)
  79. os.reboot()
  80. end
  81. end
  82.  
  83. function checkInp()
  84. if #inp == #code then
  85. for f = 1,#code do
  86. if inp[f] == code[f] then
  87. if f == #code then
  88. m.setCursorPos(3,4)
  89. m.setBackgroundColor(colors.lime)
  90. m.write(" CORRECT! ")
  91. rs.setOutput(redstoneSide,true)
  92. open()
  93. end
  94. else
  95. m.setCursorPos(3,4)
  96. m.setBackgroundColor(colors.red)
  97. m.write("WRONG CODE!")
  98. sleep(3)
  99. os.reboot()
  100. end
  101. end
  102. else
  103. m.setCursorPos(3,4)
  104. m.setBackgroundColor(colors.red)
  105. m.write("WRONG CODE!")
  106. sleep(3)
  107. os.reboot()
  108. end
  109. end
  110.  
  111. function input()
  112. mGUI()
  113. while true do
  114. ev, side, xPos, yPos = os.pullEvent("monitor_touch")
  115. print(xPos..":"..yPos)
  116. if ev == "monitor_touch" then
  117. if xPos > 2 and xPos < 6 and yPos == 6 then
  118. table.insert(inp,1)
  119. m.setCursorPos(sPos,4)
  120. m.write("*")
  121. sPos = sPos+1
  122. elseif xPos > 6 and xPos < 10 and yPos == 6 then
  123. table.insert(inp,2)
  124. m.setCursorPos(sPos,4)
  125. m.write("*")
  126. sPos = sPos+1
  127. elseif xPos > 10 and xPos < 14 and yPos == 6 then
  128. table.insert(inp,3)
  129. m.setCursorPos(sPos,4)
  130. m.write("*")
  131. sPos = sPos+1
  132. elseif xPos > 3 and xPos < 5 and yPos == 7 then
  133. table.insert(inp,4)
  134. m.setCursorPos(sPos,4)
  135. m.write("*")
  136. sPos = sPos+1
  137. elseif xPos > 7 and xPos < 9 and yPos == 7 then
  138. table.insert(inp,5)
  139. m.setCursorPos(sPos,4)
  140. m.write("*")
  141. sPos = sPos+1
  142. elseif xPos > 11 and xPos < 13 and yPos == 7 then
  143. table.insert(inp,6)
  144. m.setCursorPos(sPos,4)
  145. m.write("*")
  146. sPos = sPos+1
  147. elseif xPos > 3 and xPos < 5 and yPos == 8 then
  148. table.insert(inp,7)
  149. m.setCursorPos(sPos,4)
  150. m.write("*")
  151. sPos = sPos+1
  152. elseif xPos > 7 and xPos < 9 and yPos == 8 then
  153. table.insert(inp,8)
  154. m.setCursorPos(sPos,4)
  155. m.write("*")
  156. sPos = sPos+1
  157. elseif xPos > 11 and xPos < 13 and yPos == 8 then
  158. table.insert(inp,9)
  159. m.setCursorPos(sPos,4)
  160. m.write("*")
  161. sPos = sPos+1
  162. elseif xPos > 3 and xPos < 5 and yPos == 9 then
  163. inp = {}
  164. m.setCursorPos(3,4)
  165. m.write(" ")
  166. sPos = 4
  167. elseif xPos > 7 and xPos < 9 and yPos == 9 then
  168. table.insert(inp,0)
  169. m.setCursorPos(sPos,4)
  170. m.write("*")
  171. sPos = sPos+1
  172. elseif xPos > 11 and xPos < 13 and yPos == 9 then
  173. checkInp()
  174. end
  175. end
  176. end
  177. end
  178.  
  179. input()
Add Comment
Please, Sign In to add comment