Muzze77

InMe_Keypad_CC

Dec 21st, 2021 (edited)
415
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.93 KB | None | 0 0
  1. pass = "1234"
  2. shell.run("clear")
  3.  
  4. sides = {"top","bottom","left","right","front","back"}
  5. mon = nil
  6. for v, k in pairs(sides) do
  7.     if peripheral.getType(k) == "monitor" then
  8.         mon = peripheral.wrap(k)
  9.     end
  10. end
  11.  
  12. if mon ~= nil then
  13.     mon.clear()
  14.    
  15.     mon.setBackgroundColor(colors.black)
  16.     mon.setTextColor(colors.green)
  17.     gx,gy = mon.getSize()
  18.    
  19.     numpad = {}
  20.     numpad[1] = {"1",2,2}
  21.     numpad[2] = {"2",4,2}
  22.     numpad[3] = {"3",6,2}
  23.     numpad[4] = {"4",2,3}
  24.     numpad[5] = {"5",4,3}
  25.     numpad[6] = {"6",6,3}
  26.     numpad[7] = {"7",2,4}
  27.     numpad[8] = {"8",4,4}
  28.     numpad[9] = {"9",6,4}
  29.     numpad[0] = {"0",4,5}
  30.    
  31.  
  32.    
  33.     for v, k in pairs(numpad) do
  34.         mon.setCursorPos(k[2],k[3])
  35.         mon.write(k[1])
  36.    
  37.    
  38.    
  39.    
  40.    
  41.    
  42.    
  43.     end
  44.     id = {}
  45.     n = 1
  46.     id[1] = {"",1,1,""}
  47.     id[2] = {"",3,1,""}
  48.     id[3] = {"",5,1,""}
  49.     id[4] = {"",7,1,""}
  50.     defB = colors.black
  51.     defT = colors.green
  52.    
  53.     function mbut(cx,cy,text,bcol,tcol)
  54.         if bcol == nil then
  55.             bcol = defB
  56.         end
  57.         if tcol == nil then
  58.             tcol = defT
  59.         end
  60.        
  61.         mon.setCursorPos(cx,cy)
  62.         mon.setBackgroundColor(bcol)
  63.         mon.setTextColor(tcol)
  64.         mon.write(text)
  65.         mon.setBackgroundColor(defB)
  66.         mon.setTextColor(defT)
  67.    
  68.     end
  69.    
  70.    
  71.     while true do
  72.    
  73.    
  74.     if n > 4 then
  75.     sleep(1)
  76.    
  77.    
  78.     sPass = id[1][1] .. id[2][1] .. id[3][1] .. id[4][1]
  79.     if sPass == pass then
  80.         mbut(gx,gy," ",colors.green,nil)
  81.         rs.setOutput("right",true)
  82.         sleep(2)
  83.        
  84.         mbut(gx,gy," ",colors.black,nil)
  85.         rs.setOutput("right",false)
  86.     else
  87.         mbut(gx,gy," ",colors.red,nil)
  88.             sleep(1)
  89.         mbut(gx,gy," ",colors.black,nil)
  90.     end
  91.    
  92.    
  93.     mon.setCursorPos(1,1)
  94.     mon.clearLine()
  95.     id[1] = {"",1,1}
  96.     id[2] = {"",3,1}
  97.     id[3] = {"",5,1}
  98.     id[4] = {"",7,1}
  99.     n = 1
  100.     end
  101.    
  102.    
  103.     evt = {os.pullEvent("monitor_touch")}
  104.     x = evt[3]
  105.     y = evt[4]
  106.    
  107.     for v, k in pairs(numpad) do
  108.         if k[2] == x and k[3] == y then
  109.             id[n][1] = k[1]
  110.            
  111.                 mbut(id[n][2],id[n][3],id[n][1],nil,colors.red)
  112.             n = n + 1
  113.         end
  114.     end
  115.    
  116.    
  117.    
  118.     end
  119.  
  120. end
Add Comment
Please, Sign In to add comment