Advertisement
NanoBob

lock

Apr 22nd, 2015
321
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.81 KB | None | 0 0
  1. local redstoneSide="bottom"
  2. local buttons=peripheral.wrap("monitor_2")
  3. local display=peripheral.wrap("monitor_3")
  4.  
  5. if buttons==nil then
  6.     buttons=peripheral.wrap("monitor_5")
  7.     display=peripheral.wrap("monitor_4")
  8. end
  9.  
  10. local password="666"
  11. local code={}
  12.  
  13. os.loadAPI("button")
  14.  
  15. function drawInput()
  16.     display.clear()
  17.     local screenx,screeny=display.getSize()
  18.     local numberCount=#code
  19.     for i=1,numberCount do
  20.         display.setCursorPos(screenx/2-1,screeny/(numberCount+1)*i)
  21.         display.write("*")
  22.     end
  23. end
  24.  
  25. function addNumber(buttonName)
  26.     if buttonName=="X" then
  27.         code={}    
  28.         drawInput()
  29.     elseif buttonName==">" then
  30.         local input=""
  31.         for id,number in ipairs(code) do
  32.             input=input..number
  33.         end
  34.         if tostring(input)==password then
  35.             code={}    
  36.             drawInput()
  37.             redstone.setOutput(redstoneSide,true)
  38.             sleep(5)
  39.             redstone.setOutput(redstoneSide,false)
  40.         else
  41.             code={}    
  42.             drawInput()
  43.         end
  44.        
  45.     else
  46.         code[#code+1]=buttonName
  47.         drawInput()
  48.     end
  49. end
  50.  
  51. function setup()
  52.     button.setMonitor(buttons)
  53.     button.addButton(1,1,6,3,"1",addNumber,false,false,128,128)
  54.     button.addButton(7,1,6,3,"2",addNumber,false,false,128,128)
  55.     button.addButton(13,1,6,3,"3",addNumber,false,false,128,128)
  56.     button.addButton(1,4,6,3,"4",addNumber,false,false,128,128)
  57.     button.addButton(7,4,6,3,"5",addNumber,false,false,128,128)
  58.     button.addButton(13,4,6,3,"6",addNumber,false,false,128,128)
  59.     button.addButton(1,7,6,3,"7",addNumber,false,false,128,128)
  60.     button.addButton(7,7,6,3,"8",addNumber,false,false,128,128)
  61.     button.addButton(13,7,6,3,"9",addNumber,false,false,128,128)
  62.     button.addButton(1,10,6,3,"X",addNumber,false,false,16384,16384)
  63.     button.addButton(7,10,6,3,"0",addNumber,false,false,128,128)
  64.     button.addButton(13,10,6,3,">",addNumber,false,false,8192,8192)
  65. end
  66. setup()
  67.  
  68. while true do
  69.     button.run()
  70. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement