Advertisement
Guest User

startup

a guest
Jul 19th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.41 KB | None | 0 0
  1. -- Set monitor loc
  2. local mon = peripheral.wrap("right")
  3. -- Set password
  4. local pass = "4523"
  5. local passlen = string.len(pass)
  6. local press = "";
  7. tblpad = {};
  8. for i=0,10 do
  9. tblpad[i] = {}
  10.     for x=0,10 do
  11.         tblpad[i][x] = "x"
  12.     end
  13. end
  14.  
  15.  
  16. tblpad[2][2] = "1"
  17. tblpad[4][2] = "2"
  18. tblpad[6][2] = "3"
  19. tblpad[2][3] = "4"
  20. tblpad[4][3] = "5"
  21. tblpad[6][3] = "6"
  22. tblpad[2][4] = "7"
  23. tblpad[4][4] = "8"
  24. tblpad[6][4] = "9"
  25. tblpad[4][5] = "0"
  26.  
  27. function drawpad()
  28.     mon.setBackgroundColor(colors.green)
  29.     mon.setCursorPos(1,1)
  30.     mon.write(" Zugang ")
  31.     mon.setCursorPos(1,2)
  32.     mon.write(" 1 2 3  ")
  33.     mon.setCursorPos(1,3)
  34.     mon.write(" 4 5 6 ")
  35.     mon.setCursorPos(1,4)
  36.     mon.write(" 7 8 9 ")
  37.     mon.setCursorPos(1,5)
  38.     mon.write("   0   ")
  39. end
  40.  
  41. function countdown(c)
  42.  
  43.     for i=1,c do
  44.         mon.setCursorPos(1,1)
  45.         mon.write("       ")
  46.         mon.setCursorPos(1,2)
  47.         mon.write("       ")
  48.         mon.setCursorPos(1,3)
  49.         mon.write("   ".. c .."   ")
  50.         mon.setCursorPos(1,4)
  51.         mon.write("       ")
  52.         mon.setCursorPos(1,5)
  53.         mon.write("       ")
  54.         sleep(1)
  55.         c = c-1
  56.     end
  57. end
  58.  
  59. function dots()
  60.     mon.setBackgroundColor(colors.red)
  61.     mon.setCursorPos(1,1)
  62.     mon.write("       ")
  63.     mon.setCursorPos(1,2)
  64.     mon.write("       ")
  65.     mon.setCursorPos(1,3)
  66.     mon.write("  ...  ")
  67.     mon.setCursorPos(1,4)
  68.     mon.write("       ")
  69.     mon.setCursorPos(1,5)
  70.     mon.write("       ")
  71. end
  72.  
  73.  
  74. function opendoor()
  75. dots()
  76.     --Open Door Code
  77.     countdown(5)
  78.     redstone.setOutput(back)
  79.  dots()
  80.  
  81.     --Close Door Code
  82.     drawpad()
  83.  redstone.setOutput(back)
  84. end
  85.  
  86. function wrongpass()
  87.     mon.setBackgroundColor(colors.red)
  88.     mon.setCursorPos(1,1)
  89.     mon.write("       ")
  90.     mon.setCursorPos(1,2)
  91.     mon.write(" Falsch ")
  92.     mon.setCursorPos(1,3)
  93.     mon.write("       ")
  94.     mon.setCursorPos(1,4)
  95.     mon.write(" Code! ")
  96.     mon.setCursorPos(1,5)
  97.     mon.write("       ")
  98.     sleep(2)
  99.     countdown(5)
  100.     drawpad()
  101. end
  102. drawpad()
  103.  
  104. while true do
  105.     event, side, xPos, yPos = os.pullEvent("monitor_touch")
  106.     if tblpad[xPos][yPos] ~= "x" then
  107.         mon.setCursorPos(xPos, yPos)
  108.         mon.setBackgroundColor(colors.red)
  109.         mon.write(tblpad[xPos][yPos])
  110.         sleep(0.2)
  111.         mon.setCursorPos(xPos, yPos)
  112.         mon.setBackgroundColor(colors.green)
  113.         mon.write(tblpad[xPos][yPos])
  114.         press = press .. tblpad[xPos][yPos]
  115.         if string.len(press) == passlen and press == pass then
  116.             press = ""
  117.             opendoor()
  118.         elseif string.len(press) == passlen and press ~= pass then
  119.             press = ""
  120.             wrongpass()
  121.         end
  122.     end
  123. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement