Advertisement
dadragon84

lock

Apr 30th, 2023 (edited)
897
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. ]]
  9.  
  10.  
  11. -- Determine where the modem is.   peripheral.wrap ("monitor_2")
  12. monitorSide = nil
  13. print("Looking for monitor,")
  14. if peripheral.isPresent("left") and peripheral.getType("left")=="monitor"  then
  15.   monitorSide = "left"
  16. elseif peripheral.isPresent("right") and peripheral.getType("right")=="monitor" then
  17.   monitorSide = "right"
  18. elseif peripheral.isPresent("top") and peripheral.getType("top")=="monitor" then
  19.   monitorSide = "top"
  20. elseif peripheral.isPresent("back") and peripheral.getType("back")=="monitor" then
  21.   monitorSide = "back"
  22. elseif peripheral.isPresent("bottom") and peripheral.getType("bottom")=="monitor" then
  23.   monitorSide = "bottom"
  24.  elseif peripheral.isPresent("front") and peripheral.getType("front")=="monitor" then
  25.   monitorSide = "front"
  26. else
  27.     print("No Monitor Found!")
  28.     monitorSide = false
  29.     end
  30.  
  31. while monitorSide == false do
  32.     print("No Monitor Found!")
  33.     print("ERROR: "..math.random(1,300))
  34.     sleep(5)
  35.     shell.run("lock")
  36. end
  37.  
  38.  
  39. os.pullEvent = os.pullEventRaw
  40. term.clear()
  41. term.setCursorPos(1,1)
  42. shell.openTab("lock2")
  43. sleep(0.1)
  44. shell.switchTab(2)
  45. bundleErrorColor = colors.red
  46. bundleSuccessColor = colors.lime
  47.  
  48.  
  49. m = peripheral.wrap( tostring(monitorSide) )
  50. m.clear()
  51. m.setTextScale(0.5)
  52. m.setBackgroundColor(colors.black)
  53. m.setTextColor(colors.white)
  54.  
  55.  
  56.  
  57. load = fs.open("Config", "r")
  58. code,autoReset,waitTime,redstoneSide = unpack(textutils.unserialize(load.readAll()))
  59. load.close()
  60.                
  61. inp = {}
  62. sPos = 4
  63.  
  64.  
  65. function mGUI()
  66.     gui = {
  67.         [[  ?John Dowe   ]],
  68.         [[ Security INC. ]],
  69.         [[ +-----------+ ]],
  70.         [[ |           | ]],
  71.         [[ +---+---+---+ ]],
  72.         [[ | 1 | 2 | 3 | ]],
  73.         [[ | 4 | 5 | 6 | ]],
  74.         [[ | 7 | 8 | 9 | ]],
  75.         [[ | ?? | 0 | > | ]],
  76.         [[ +---+---+---+ ]],
  77.     }
  78.     m.setTextColor(colors.red)
  79.     for i = 1,10 do
  80.         m.setCursorPos(1,i)
  81.         if i == 3 then
  82.             m.setTextColor(colors.white)
  83.         end
  84.         m.write(gui[i])
  85.     end
  86.     m.setCursorPos(3,9)
  87.     m.setBackgroundColor(colors.red)
  88.     m.write(" >< ")
  89.     m.setCursorPos(11,9)
  90.     m.setBackgroundColor(colors.lime)
  91.     m.write(" <> ")
  92.     m.setCursorPos(3,4)
  93.     m.setBackgroundColor(colors.blue)
  94.     m.write("           ")
  95. end
  96.  
  97. function open()
  98.     if autoReset then
  99.         if waitTime == 0 then waitTime = 2 end
  100.         sleep(waitTime)
  101.         rs.setBundledOutput(redstoneSide,0)
  102.         os.reboot()
  103.     else
  104.         m.setBackgroundColor(colors.black)
  105.         m.clear()
  106.         m.setTextScale(5)
  107.         m.setCursorPos(1,1)
  108.         m.write("<")
  109.         ev, side, xPos, yPos = os.pullEvent("monitor_touch")
  110.         rs.setBundledOutput(redstoneSide,0)
  111.         os.reboot()
  112.     end
  113. end
  114.  
  115. function checkInp()
  116.     if #inp == #code then
  117.         for f = 1,#code do
  118.             if inp[f] == code[f] then
  119.                 if f == #code then
  120.                     m.setCursorPos(3,4)
  121.                     m.setBackgroundColor(colors.lime)
  122.                     m.write(" WELCOME!  ")
  123.                     rs.setBundledOutput(redstoneSide,bundleSuccessColor)
  124.                     open()
  125.                 end
  126.             else
  127.                 m.setCursorPos(3,4)
  128.                 m.setBackgroundColor(colors.red)
  129.                 m.write("WRONG CODE!")
  130.                 rs.setBundledOutput(redstoneSide,bundleErrorColor)
  131.                 sleep(10)
  132.                 os.reboot()
  133.             end
  134.         end
  135.     else
  136.         m.setCursorPos(3,4)
  137.         m.setBackgroundColor(colors.red)
  138.         m.write("WRONG CODE!")
  139.         rs.setBundledOutput(redstoneSide, bundleErrorColor)
  140.         sleep(10)
  141.         os.reboot()
  142.     end
  143. end
  144.  
  145. function input()
  146.     mGUI()
  147.     while true do
  148.         ev, side, xPos, yPos = os.pullEvent("monitor_touch")
  149.         print(xPos..":"..yPos)
  150.         if ev == "monitor_touch" then
  151.             if xPos > 2 and xPos < 6 and yPos == 6 then
  152.                 table.insert(inp,1)
  153.                 m.setCursorPos(sPos,4)
  154.                 m.write("*")
  155.                 sPos = sPos+1
  156.             elseif xPos > 6 and xPos < 10 and yPos == 6 then
  157.                 table.insert(inp,2)
  158.                 m.setCursorPos(sPos,4)
  159.                 m.write("*")
  160.                 sPos = sPos+1
  161.             elseif xPos > 10 and xPos < 14 and yPos == 6 then
  162.                 table.insert(inp,3)
  163.                 m.setCursorPos(sPos,4)
  164.                 m.write("*")
  165.                 sPos = sPos+1
  166.             elseif xPos > 3 and xPos < 5 and yPos == 7 then
  167.                 table.insert(inp,4)
  168.                 m.setCursorPos(sPos,4)
  169.                 m.write("*")
  170.                 sPos = sPos+1
  171.             elseif xPos > 7 and xPos < 9 and yPos == 7 then
  172.                 table.insert(inp,5)
  173.                 m.setCursorPos(sPos,4)
  174.                 m.write("*")
  175.                 sPos = sPos+1
  176.             elseif xPos > 11 and xPos < 13 and yPos == 7 then
  177.                 table.insert(inp,6)
  178.                 m.setCursorPos(sPos,4)
  179.                 m.write("*")
  180.                 sPos = sPos+1
  181.             elseif xPos > 3 and xPos < 5 and yPos == 8 then
  182.                 table.insert(inp,7)
  183.                 m.setCursorPos(sPos,4)
  184.                 m.write("*")
  185.                 sPos = sPos+1
  186.             elseif xPos > 7 and xPos < 9 and yPos == 8 then
  187.                 table.insert(inp,8)
  188.                 m.setCursorPos(sPos,4)
  189.                 m.write("*")
  190.                 sPos = sPos+1
  191.             elseif xPos > 11 and xPos < 13 and yPos == 8 then
  192.                 table.insert(inp,9)
  193.                 m.setCursorPos(sPos,4)
  194.                 m.write("*")
  195.                 sPos = sPos+1
  196.             elseif xPos > 3 and xPos < 5 and yPos == 9 then
  197.                 inp = {}
  198.                 m.setCursorPos(3,4)
  199.                 m.write("           ")
  200.                 sPos = 4
  201.             elseif xPos > 7 and xPos < 9 and yPos == 9 then
  202.                 table.insert(inp,0)
  203.                 m.setCursorPos(sPos,4)
  204.                 m.write("*")
  205.                 sPos = sPos+1
  206.             elseif xPos > 11 and xPos < 13 and yPos == 9 then
  207.                 checkInp()
  208.             end
  209.         end
  210.     end
  211. end
  212.  
  213. input()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement