Advertisement
Guest User

autorun.lua

a guest
Jul 20th, 2019
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.35 KB | None | 0 0
  1. local component = require("component")
  2. local event = require("event")
  3. local modem = component.modem
  4. local computer = require("computer")
  5. local door = component.os_doorcontroller
  6. local locked = false
  7. modem.open(255)
  8. function open()
  9.   if not locked then
  10.     door.open()
  11.   end
  12. end
  13. function close()
  14.   if not locked then
  15.     door.close()
  16.   end
  17. end
  18. component.redstone.setOutput(1, 0)
  19. function lock()
  20.   locked = true
  21.   component.redstone.setOutput(1, 1)
  22. end
  23. function unlock()
  24.   locked = false
  25.   component.redstone.setOutput(1, 0)
  26. end
  27. local name = "lowsec"
  28. while true do
  29.   local event, a, b, c, d, e = event.pull()
  30.   if event == "modem_message" then
  31.     if e == name.."_open" then
  32.       print("[M] Opening...")
  33.       open()
  34.     elseif e == name.."_close" then
  35.       print("[M] Closing...")
  36.       close()
  37.     elseif e == name.."_lock" then
  38.       print("[M] Locking...")
  39.       lock()
  40.     elseif e == name.."_unlock" then
  41.       print("[M] Unlocking...")
  42.       unlock()
  43.     elseif e == name.."_beep" then
  44.       print("[M] Beeping...")
  45.       computer.beep(500,1)
  46.     end
  47.   end
  48.   if event == "redstone_changed" then
  49.     if d == 15 then
  50.       print("[R] Opening...")
  51.       open()
  52.     elseif d == 0 then
  53.       print("[R] Closing...")
  54.       close()
  55.     end
  56.   end
  57.   if event == "magData" then
  58.     print("[C] Card swiped!")
  59.     local data = b
  60.     modem.broadcast(256, name.."_mdata", data)
  61.   end
  62. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement