grand_mind1

Passcode Monitor

Jul 8th, 2014
399
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.57 KB | None | 0 0
  1. os.loadAPI("btn")
  2. mon = peripheral.wrap("top")
  3. rednet.open("right")
  4.  
  5. local serverID = 121
  6. local curPass = ""
  7. local pass
  8. local passLength = 0
  9.  
  10. local id
  11. local msg
  12.  
  13. local event
  14. local button
  15. local x
  16. local y
  17.  
  18. function addNumber(number)
  19.     if passLength+1 <= 10 then
  20.         passLength = passLength+1
  21.         curPass = curPass..number
  22.     end
  23. end
  24.  
  25. function delNumber()
  26.     if passLength-1 >= 0 then
  27.         passLength = passLength-1
  28.         curPass = string.sub(curPass, -#curPass, #curPass-1)
  29.     end
  30. end
  31.  
  32. function blank()
  33.  
  34. end
  35.  
  36. local function mainScreen()
  37.     mon.setTextScale(1)
  38.     local yPos = 5
  39.     mon.setBackgroundColor(colors.lightGray)
  40.     mon.clear()
  41.     mon.setCursorPos(1,1)
  42.     btn.createScreen()
  43.  
  44.     mon.setBackgroundColor(colors.gray)
  45.  
  46.     for i = 1,5 do
  47.         mon.setCursorPos(24,yPos)
  48.         for i = 24,47 do
  49.             mon.write(" ")
  50.         end
  51.         yPos = yPos+1
  52.     end
  53.  
  54.     mon.setCursorPos(25, 7)
  55.     mon.setBackgroundColor(colors.black)
  56.     for i = 25,46 do
  57.         mon.write(" ")
  58.     end
  59.  
  60.     mon.setCursorPos(27,7)
  61.    
  62.     for i = 1,passLength do
  63.         mon.write("*")
  64.     end
  65. end
  66.  
  67. function checkPass()
  68.     rednet.send(serverID, curPass)
  69.     curPass = ""
  70.     passLength = 0
  71.     mainScreen()
  72.     id, msg, dis = rednet.receive(10)
  73.     if id == serverID and msg == "Correct" then
  74.         print("Correct")
  75.         mon.clear()
  76.         mon.setTextScale(4)
  77.         btn.centerText(3,"Dont Move!!",colors.white)
  78.         sleep(.5)
  79.         mon.clear()
  80.         btn.centerText(3,"Dont Move!!",colors.white)
  81.         sleep(.5)
  82.         rs.setOutput("left",true)
  83.         sleep(1)
  84.         rs.setOutput("right",true)
  85.         sleep(2)
  86.         rs.setOutput("right",false)
  87.         sleep(1)
  88.         rs.setOutput("left",false)
  89.     else
  90.         print("Incorrect")
  91.     end
  92. end
  93.  
  94. btn.fillTable("1",4,8,2,6,"1",addNumber,colors.green,true)
  95. btn.fillTable("2",10,14,2,6,"2",addNumber,colors.green,true)
  96. btn.fillTable("3",16,20,2,6,"3",addNumber,colors.green,true)
  97. btn.fillTable("4",4,8,8,12,"4",addNumber,colors.green,true)
  98. btn.fillTable("5",10,14,8,12,"5",addNumber,colors.green,true)
  99. btn.fillTable("6",16,20,8,12,"6",addNumber,colors.green,true)
  100. btn.fillTable("7",4,8,14,18,"7",addNumber,colors.green,true)
  101. btn.fillTable("8",10,14,14,18,"8",addNumber,colors.green,true)
  102. btn.fillTable("9",16,20,14,18,"9",addNumber,colors.green,true)
  103. btn.fillTable("0",10,14,20,24,"0",addNumber,colors.green,true)
  104. btn.fillTable("blank1",4,8,20,24," ",blank,colors.green,true)
  105. btn.fillTable("blank2",16,20,20,24," ",blank,colors.green,true)
  106. btn.fillTable("enter",24,47,11,15,"Enter",checkPass,colors.lime,true)
  107. btn.fillTable("delete",24,47,17,21,"Delete ",delNumber,colors.red,true)
  108.  
  109. while true do
  110.     mainScreen()
  111.     event, button, x, y = os.pullEvent("monitor_touch")
  112.     btn.checkClick(x,y)
  113. end
Advertisement
Add Comment
Please, Sign In to add comment