Advertisement
Guest User

startup

a guest
Jul 17th, 2015
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.76 KB | None | 0 0
  1. --Run keydetect--
  2. shell.run(".keydetect")
  3.  
  4. --Chatbox stuff--
  5. chatboxFound = false
  6. if peripheral.find("chatbox") then
  7.   chatbox = peripheral.find("chatbox")
  8.   chatbox.setLabel("ZiR")
  9.   chatbox.tell("_Zircon_","Computer ID: "..os.getComputerID().." started!")
  10.   chatboxFound = true
  11. end
  12.  
  13. --Modem Stuff--
  14. local modem = peripheral.wrap("back")
  15. modem.open(5)
  16.  
  17. --The Code--
  18. os.pullEvent = os.pullEventRaw
  19. local players = "_Zircon_"
  20. local failSleep = 2
  21. local successSleep = 2
  22. local doorLoc = "left"
  23.  
  24. while true do
  25.   function start()
  26.     if term.isColor() then
  27.       term.setBackgroundColor(colors.green)
  28.       term.setTextColor(colors.lime)
  29.     end
  30.     term.clear()
  31.     term.setCursorPos(1,1)
  32.   end
  33.   start()
  34.   print("Only "..players.." can unlock this door!")
  35.   local event, side, player = os.pullEvent()
  36.   if event == "player" and players:find(player) then
  37.     term.setTextColor(colors.lightBlue)
  38.     print("Door Unlocked!")
  39.     rs.setOutput(doorLoc, true)
  40.     sleep(successSleep)
  41.     rs.setOutput(doorLoc, false)
  42.     start()
  43.   elseif event == "player" then
  44.     term.setTextColor(colors.red)
  45.     print("Sorry, only "..players.." can unlock this door!")
  46.     print("Sleeping for "..failSleep.." seconds")
  47.     sleep(failSleep)
  48.     start()
  49.   end
  50.   local event, modemSide, senderChannel, replyChannel, message, senderDistance = os.pullEvent("modem_message")
  51.   if event == "modem_message" then
  52.     if modemSide == "back" then
  53.       if senderChannel == 5 then
  54.         if replyChannel == 5 then
  55.           if message == "housedooropen" then
  56.             rs.setOutput(doorLoc, true)
  57.             sleep(successSleep)
  58.             rs.setOutput(doorLoc, false)
  59.             modem.transmit(5,5,"Door Unlocked!")
  60.           end
  61.         end
  62.       end
  63.     end
  64.   end
  65. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement