Advertisement
Guest User

Untitled

a guest
Jun 16th, 2016
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.23 KB | None | 0 0
  1. local component = component or require("component")
  2. local computer = computer or require("computer")
  3. local user = { "TheCryptek", "user2", "user3", "_inari" }
  4.  
  5. local red = component.proxy(component.list("redstone")())
  6. local scr = {}
  7. local gpu = {}
  8.  
  9. for a in component.list("screen") do table.insert(scr, a) end
  10. for a in component.list("gpu") do table.insert(gpu, component.proxy(a)) end
  11. for i = 1, #gpu do gpu[i].bind(scr[i]) end
  12.  
  13. function showState(s)
  14.   for i, g in ipairs(gpu) do
  15.     g.setResolution(40, 20)
  16.     g.fill(1, 1, 40, 20, " ")
  17.     if s then
  18.       g.setForeground(0x00FF00)
  19.       g.set(16, 10, "Access denied")
  20.     else
  21.       g.setForeground(0xFF0000)
  22.       g.set(16, 10, "Access granted")
  23.     end
  24.   end
  25. end
  26.  
  27. function sleep(x)
  28.   local tgt = computer.uptime() + x
  29.   while computer.uptime() < tgt do
  30.     computer.pullSignal(tgt - computer.uptime())
  31.   end
  32. end
  33.  
  34. while true do
  35.   showState(false)
  36.   local type, _, x, y, btn, nick = computer.pullSignal(5)
  37.   if type == "touch" then
  38. error(nick)
  39.     nick = nick:lower()
  40.     for i, v in ipairs(user) do
  41.       if v == nick then
  42.         showState(true)
  43.         red.setOutput(1, 255)
  44.         sleep(2)
  45.         red.setOutput(1, 0)
  46.       end
  47.     end
  48.   end
  49. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement