Advertisement
Nezn

Android Lock [OC]

Jul 24th, 2015
1,679
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.48 KB | None | 0 0
  1. local component = require("component")
  2. local g = component.gpu
  3. local term = require("term")
  4. local colors = require("colors")
  5. local event = require("event")
  6. local red = component.redstone
  7. local sides = require("sides")
  8.  
  9. local code = "125879"
  10. local input = ""
  11. local delay = 2
  12. local side = 3
  13. local show = true
  14.  
  15. args = {...}
  16. if args[1] ~= nil and args[1] ~= "_" then
  17.         code = args[1]
  18. end
  19. if args[2] ~= nil and args[2] ~= "_" then
  20.         for i=0,5 do
  21.                 if sides[i] == args[2] then
  22.                         side = i
  23.                         break
  24.                 end
  25.         end
  26. end
  27. if args[3] ~= nil and args[3] ~= "_" then
  28.         delay = tonumber(args[3])
  29. end
  30. if args[4] ~= nil and args[4] == "false" then
  31.         show = false
  32. end
  33.  
  34. g.setResolution(30,15)
  35.  
  36. g.setBackground(colors.silver, true)
  37. term.clear()
  38.  
  39. function drawDot(number, color)
  40.         local x = 3+math.fmod(number+2,3)*10
  41.         local y = 2+(math.ceil(number/3)-1)*5
  42.         g.setBackground(color, true)
  43.         g.fill(x,y,6,3," ")
  44.         g.setBackground(colors.white, true)
  45.         g.fill(x+2,y+1,2,1," ")
  46. end
  47.  
  48. function drawDots()
  49.         for i=1,9 do
  50.                 drawDot(i,colors.cyan)
  51.         end
  52. end
  53.  
  54. drawDots()
  55.  
  56. local doing = false
  57. while true do
  58.         local event, _, x, y = event.pull(0.3)
  59.         if event == "touch" then
  60.                 if not doing then
  61.                         doing = true
  62.                 end
  63.                 if (not show and math.fmod(x, 10) > 2 and math.fmod(x, 10) < 9 and math.fmod(y, 5) > 1 and math.fmod(y, 5) < 5) or show then
  64.                         local button = (math.ceil(y/5)-1)*3+math.ceil((x)/10)
  65.                         if show then
  66.                                 drawDot(button, colors.lime)
  67.                         end
  68.                         if string.find(input, tostring(button)) == nil then
  69.                                 input = input..tostring(button)
  70.                         end
  71.                 end
  72.         elseif event == nil then
  73.                 if doing then
  74.                         if show then
  75.                                 drawDots()
  76.                         end
  77.                         if input == code then
  78.                                 red.setOutput(side, 15)
  79.                                 os.sleep(delay)
  80.                                 red.setOutput(side, 0)
  81.                         end
  82.                         input = ""
  83.                         doing = false
  84.                 end
  85.         end
  86. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement