MoonlightOwl

Door Lock Client by Totoro

Aug 26th, 2014
961
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- Door lock client by Totoro
  2. -- 15.07.2014
  3. port = 27
  4.  
  5. local event = require('event')
  6. local serial = require('serialization')
  7. local sides = require('sides')
  8. local com = require('component')
  9. local modem = com.modem
  10. local gpu = com.gpu
  11. local redstone = com.redstone
  12.  
  13. gpu.setResolution(14,7)
  14. width, height = gpu.getResolution()
  15.  
  16. function square(color)
  17.   gpu.fill(1, 1, width, height, ' ')
  18.   gpu.setBackground(color)
  19.   gpu.fill(3, 2, width-4, height-2, ' ')
  20.   gpu.setBackground(0x000000)
  21.   gpu.set(6,4, "Push")
  22. end
  23. function openLock()
  24.   redstone.setOutput(sides.down, 15)
  25.   os.sleep(1)
  26.   redstone.setOutput(sides.down, 0)
  27. end
  28.  
  29. square(0x005000)
  30. modem.open(port)
  31.  
  32. while true do
  33.   name, address, a, b, c, username, e = event.pull()
  34.   if name == "key_down" then
  35.     break
  36.   elseif name == "touch" then
  37.     modem.broadcast(port, serial.serialize({"lock", username}))
  38.   elseif name == "modem_message" then
  39.     if username == "lock_open" then
  40.       openLock()
  41.     elseif username == "lock_deny" then
  42.       square(0xFF0000)
  43.       os.sleep(0.8)
  44.       square(0x005000)
  45.     end
  46.   else --print(name)
  47.   end
  48. end
  49.  
  50. gpu.setResolution(80,24)
  51. gpu.fill(1, 1, 80, 24, ' ')
  52. modem.close(port)
RAW Paste Data