dadragon84

lock

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