IoIiderp

rednet door server

Jun 1st, 2021 (edited)
930
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.74 KB | None | 0 0
  1. local distance = 6.4
  2. local modemSide = "top"
  3. local outputSide = "front"
  4. local flipped = false
  5.  
  6.  
  7. local amountInactive = 0
  8.  
  9. function inactiveLoop()
  10.     while true do
  11.         os.sleep(.2)
  12.         amountInactive = amountInactive + 1
  13.  
  14.         if amountInactive >= 4 then
  15.             amountInactive = 4
  16.             redstone.setOutput(outputSide, not flipped)
  17.         end
  18.     end
  19. end
  20.  
  21. function mainLoop()
  22.     local modem = peripheral.wrap(modemSide)
  23.     modem.open(188)
  24.     while true do
  25.         local event, modemSide, senderChannel, replyChannel, message, senderDistance = os.pullEvent("modem_message")
  26.         if message == "opendoor" and senderDistance <= distance then
  27.             amountInactive = 0
  28.             redstone.setOutput(outputSide, flipped)
  29.         end
  30.     end
  31. end
  32.  
  33. parallel.waitForAll(inactiveLoop, mainLoop)
Add Comment
Please, Sign In to add comment