Advertisement
JaMaNi133

FlyerInterceptomatic

Aug 21st, 2024 (edited)
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.20 KB | None | 0 0
  1. holderUp = "top"
  2. holderDown = "left"
  3. feedback = "right"
  4. activator = "back"
  5. swapper = "front"
  6. networkSide = "bottom"
  7.  
  8. rednet.open(networkSide)
  9.  
  10. function waitForFlyer()
  11.     timeout = 1200
  12.     while timeout>=0 do
  13.         timeout = timeout - 1
  14.         if redstone.getInput(feedback) then
  15.             print("triggered")
  16.             return true
  17.         end
  18.         sleep(0.05)
  19.     end
  20.     print("flyer wait timed out")
  21.     return false
  22. end
  23.  
  24. function sendFlying()
  25.     redstone.setOutput(activator,true)
  26.     sleep(0.05)
  27.     redstone.setOutput(activator,false)
  28.    
  29. end
  30.  
  31.  
  32.  
  33.  
  34. rednet.open(networkSide)
  35. while rednet.isOpen() do
  36.     senderID,message,distance,protcol = rednet.receive()
  37.     print(message.command)
  38.     if message.command == "interceptor.flyer.catch" then
  39.         redstone.setOutput(holderUp,true)
  40.         redstone.setOutput(holderDown,false)
  41.         if waitForFlyer() then
  42.             redstone.setOutput(holderDown,true)
  43.             redstone.setOutput(holderUp,false)
  44.             sleep(0.4)
  45.             redstone.setOutput(holderDown,false)
  46.             redstone.setOutput(swapper,true)
  47.             sleep(1)
  48.             redstone.setOutput(swapper,false)
  49.         else
  50.             print("flyer timed out")
  51.             rednet.broadcast({command="interceptor.flyer.timeout"})
  52.             redstone.setOutput(holderUp,true)
  53.             redstone.setOutput(holderDown,false)
  54.         end
  55.         rednet.broadcast({command="interceptor.flyer.arrived"})
  56.     end
  57.  
  58.     if message.command == "interceptor.flyer.reattach" then
  59.         redstone.setOutput(holderDown,true)
  60.         if waitForFlyer() then
  61.             sleep(2)
  62.             redstone.setOutput(holderDown,false)
  63.             redstone.setOutput(swapper,true)
  64.             redstone.setOutput(holderUp,true)
  65.             sleep(2)
  66.             redstone.setOutput(holderUp,false)
  67.             sleep(1)
  68.             redstone.setOutput(swapper,false)
  69.         else
  70.             print("flyer timed out")
  71.             rednet.broadcast({command="interceptor.flyer.timeout"})
  72.             redstone.setOutput(holderDown,false)
  73.         end
  74.         rednet.broadcast({command="interceptor.flyer.attached"})
  75.     end
  76.  
  77.     if message.command == "interceptor.flyer.start" then
  78.         sendFlying()
  79.     end
  80. end
  81. print("rednet closed... terminating")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement