Advertisement
Guest User

door

a guest
Feb 8th, 2014
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.15 KB | None | 0 0
  1. --Change these sides to how you have your door configured
  2. local wirelessSide = "bottom"       --The side with the wireless modem
  3. local doorSide = "front"           --The side that you want the redstone output for your door to go
  4. local isPlayerDetector = false      --Whether there is a player detector attached to the system or not
  5. local playerDetectorSide = "right"   --The side that the player detector is inputing its redstone signal to
  6. local controllerID = 3             --The id of the computer with the monitor
  7.  
  8. function checkStatus()                 --Checks the status of the door
  9. local x = redstone.getInput(doorSide)   --gets the redsotne input of the door
  10.   if x==false then                     --tells the controller if it is open or closed
  11.     rednet.send(controllerID,"open")
  12.   elseif x==true then
  13.     rednet.send(controllerID,"closed")
  14.   end
  15. end
  16.  
  17. function playerTest()
  18.   if redstone.getInput(playerDetectorSide)==true then   --Tests to see if the player detector is on or off and opens/closes door
  19.     redstone.setOutput(doorSide,false)
  20.     checkStatus()
  21.   elseif redstone.getInput(playerDetectorSide)==false then
  22.     redstone.setOutput(doorSide, true)
  23.     checkStatus()
  24.   end
  25. end
  26.  
  27. rednet.open(wirelessSide)                    --Opens the router for rednet signals
  28.  
  29. while true do
  30.   checkStatus()
  31.   if isPlayerDetector==true then
  32.     playerTest()
  33.   end
  34.   sleep(.1)                                  --Sleep added so that the computer doesn't return an error
  35.   senderId1, msg1, dist1 = rednet.receive(1) --Checks to see if a rednet signal is received to force it open
  36.   if senderId1==controllerID and msg1=="force2" then    --If it returns a signal it forces door1 open
  37.     redstone.setOutput(doorSide,false)
  38.     sleep(.1)
  39.     checkStatus()                            --Updates controller on status
  40.     isOpen=1
  41.     senderId2, msg2, dist2 = rednet.receive() --Waits for signal to stop force opening door1
  42.   end  
  43.   if (senderId2==controllerID and msg2=="force2") and isOpen==1 then --Stops force opening the door and updates controller on status
  44.     redstone.setOutput(doorSide,true)
  45.     sleep(.1)
  46.     checkStatus()
  47.     isOpen=0
  48.   end
  49. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement