Advertisement
smilerryan

[LUA] ComputerCraft PIN Display

Sep 23rd, 2018
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.96 KB | None | 0 0
  1. -- ComputerCraft PIN Display
  2. -- Install: pastebin get ewAZEHGu /startup
  3.  
  4. local mon = peripheral.wrap("top")
  5. local pass = "0000"
  6.  
  7. local passlen = string.len(pass)
  8. local press = "";
  9. tblpad = {};
  10. for i=0,10 do
  11. tblpad[i] = {}
  12.     for x=0,10 do
  13.         tblpad[i][x] = "x"
  14.     end
  15. end
  16.  
  17. tblpad[2][2] = "1"
  18. tblpad[4][2] = "2"
  19. tblpad[6][2] = "3"
  20. tblpad[2][3] = "4"
  21. tblpad[4][3] = "5"
  22. tblpad[6][3] = "6"
  23. tblpad[2][4] = "7"
  24. tblpad[4][4] = "8"
  25. tblpad[6][4] = "9"
  26. tblpad[4][5] = "0"
  27.  
  28. function drawpad()
  29.     if  term.isColor() then
  30.         mon.setBackgroundColor(colors.green)
  31.     end
  32.     mon.setCursorPos(1,1)
  33.     mon.write("x-----x")
  34.     mon.setCursorPos(1,2)
  35.     mon.write("|1 2 3|")
  36.     mon.setCursorPos(1,3)
  37.     mon.write("|4 5 6|")
  38.     mon.setCursorPos(1,4)
  39.     mon.write("|7 8 9|")
  40.     mon.setCursorPos(1,5)
  41.     mon.write("x--0--x")
  42. end
  43.  
  44. function countdown(c)
  45.     for i=1,c do
  46.     if  term.isColor() then
  47.         mon.setBackgroundColor(colors.green)
  48.     end
  49.         mon.setCursorPos(1,1)
  50.         mon.write("       ")
  51.         mon.setCursorPos(1,2)
  52.         mon.write("       ")
  53.         mon.setCursorPos(1,3)
  54.         mon.write("  [".. c .."]  ")
  55.         mon.setCursorPos(1,4)
  56.         mon.write("       ")
  57.         mon.setCursorPos(1,5)
  58.         mon.write("       ")
  59.         sleep(1)
  60.         c = c-1
  61.     end
  62. end
  63.  
  64. function dots()
  65.     if  term.isColor() then
  66.         mon.setBackgroundColor(colors.red)
  67.     end
  68.     mon.setCursorPos(1,1)
  69.     mon.write("       ")
  70.     mon.setCursorPos(1,2)
  71.     mon.write("       ")
  72.     mon.setCursorPos(1,3)
  73.     mon.write("  ...  ")
  74.     mon.setCursorPos(1,4)
  75.     mon.write("       ")
  76.     mon.setCursorPos(1,5)
  77.     mon.write("       ")
  78. end
  79.  
  80.  
  81. function opendoor()
  82. dots()
  83. redstone.setOutput("top", true)
  84. redstone.setOutput("left", true)
  85. redstone.setOutput("right", true)
  86. redstone.setOutput("bottom", true)
  87. redstone.setOutput("front", true)
  88. redstone.setOutput("back", true)
  89. countdown(5)
  90. redstone.setOutput("top", false)
  91. redstone.setOutput("left", false)
  92. redstone.setOutput("right", false)
  93. redstone.setOutput("bottom", false)
  94. redstone.setOutput("front", false)
  95. redstone.setOutput("back", false)
  96. dots()
  97. drawpad()
  98. end
  99.  
  100. function wrongpass()
  101.     if  term.isColor() then
  102.         mon.setBackgroundColor(colors.red)
  103.     end
  104.     mon.setCursorPos(1,1)
  105.     mon.write("       ")
  106.     mon.setCursorPos(1,2)
  107.     mon.write("INVALID")
  108.     mon.setCursorPos(1,3)
  109.     mon.write("PINCODE")
  110.     mon.setCursorPos(1,4)
  111.     mon.write("ENTERED")
  112.     mon.setCursorPos(1,5)
  113.     mon.write("       ")
  114.     sleep(4)
  115.     drawpad()
  116. end
  117. drawpad()
  118.  
  119. while true do
  120.     event, side, xPos, yPos = os.pullEvent("monitor_touch")
  121.     if tblpad[xPos][yPos] ~= "x" then
  122.         mon.setCursorPos(xPos, yPos)
  123.     if  term.isColor() then
  124.         mon.setBackgroundColor(colors.gray)
  125.     end
  126.         mon.write(tblpad[xPos][yPos])
  127.         sleep(0.2)
  128.         mon.setCursorPos(xPos, yPos)
  129.     if  term.isColor() then
  130.         mon.setBackgroundColor(colors.gray)
  131.     end     mon.write(tblpad[xPos][yPos])
  132.         press = press .. tblpad[xPos][yPos]
  133.         if string.len(press) == passlen and press == pass then
  134.             press = ""
  135.             opendoor()
  136.         elseif string.len(press) == passlen and press ~= pass then
  137.             press = ""
  138.             wrongpass()
  139.         end
  140.     end
  141. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement