Advertisement
Alexr360

Bastion Reciever Secondary

Feb 22nd, 2024 (edited)
757
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local function bastion()
  2.     local modem = peripheral.find("modem") or error("No modem attached", 0)
  3.     modem.open(15) -- Open 43 so we can receive replies
  4.  
  5.     -- And wait for a reply
  6.     local event, side, channel, replyChannel, message, distance
  7.     repeat
  8.       event, side, channel, replyChannel, message, distance = os.pullEvent("modem_message")
  9.     until channel == 15
  10.  
  11.     -- Process the received message based on its content
  12.     if message == "Bridge" then
  13.         os.sleep(1)
  14.         if redstone.getInput("left") then
  15.             modem.transmit(43, 15, "Closing Bridge Gate")
  16.         else
  17.             modem.transmit(43, 15, "Opening Bridge Gate")
  18.         end
  19.  
  20.     elseif message == "Courtyard" then
  21.         os.sleep(1)
  22.         if redstone.getInput("right") then
  23.             modem.transmit(43, 15, "Closing Courtyard Gate")
  24.         else
  25.             modem.transmit(43, 15, "Opening Courtyard Gate")
  26.         end
  27.  
  28.     elseif message == "status" then
  29.         courtyard = ""
  30.         bridge = ""
  31.         lockdown = ""
  32.         if redstone.getInput("right") then
  33.             courtyard = "Courtyard Gate Closed, "
  34.         else
  35.             courtyard = "Courtyard Gate Open, "
  36.         end
  37.         if redstone.getInput("left") then
  38.             bridge = "Bridge Gate Closed, "
  39.         else
  40.             bridge = "Bridge Gate Open, "
  41.         end
  42.         if redstone.getInput("back") then
  43.             lockdown = "Lockdown Enabled"
  44.         else
  45.             lockdown = "Lockdown Disabled"
  46.         end
  47.         modem.transmit(43, 15, courtyard .. bridge .. lockdown)
  48.  
  49.  
  50.     elseif message == "Lockdown" then
  51.         os.sleep(1)
  52.         if redstone.getInput("back") then
  53.             modem.transmit(43, 15, "Enabeling Lockdown")
  54.         else
  55.             modem.transmit(43, 15, "Disabeling Lockdown")
  56.         end
  57.     end
  58. end
  59.  
  60. term.clear()
  61. term.setCursorPos(1, 1)
  62. print("Bastion Online!")
  63.  
  64. -- Main loop
  65. while true do
  66.     bastion()
  67. end
  68.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement