Advertisement
Hystel

energy state change

Nov 23rd, 2024 (edited)
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.31 KB | None | 0 0
  1. local modem = peripheral.find("modem") or error("No modem attached!")
  2. local monitor = peripheral.wrap("monitor_2") or print("Monitor unavailable.. Status wont be indicated.")
  3. modem.open(43)
  4.  
  5. print("This is a secure environment! Please enter the password.")
  6. local input = read()
  7. if input == "verysecurepassword123" then
  8.     print("What would you like to do? SHUTDOWN or OPERATE")
  9.     local toDo = read()
  10.     if toDo == "SHUTDOWN" then
  11.         if monitor then
  12.             monitor.clear()
  13.             monitor.setCursorPos(1,1)
  14.             monitor.write("SHUTDOWN SEQUENCE")
  15.         end
  16.         print("SHUTDOWN sequence initiated!")
  17.         sleep(1)
  18.         modem.transmit(43, 43, "SHUTDOWN")
  19.         while true do
  20.             local event, side, channel, replyChannel, message, distance = os.pullEvent("modem_message")
  21.             if channel == 45 then
  22.                 local identifier, action = message:match("^(%w+)%s+(%d+)$")
  23.                 if action == "SHUTDOWN" then
  24.                     if monitor then
  25.                         local cx, cy = monitor.getCursorPos()
  26.                         monitor.setCursorPos(cx + 1, cy + 1)
  27.                         monitor.write(identifier .. " HAS SHUT DOWN")
  28.                     end
  29.                     print(identifier .. " HAS SHUT DOWN")
  30.                 end
  31.             end
  32.             sleep(0.5)
  33.         end
  34.     elseif toDo == "OPERATE" then
  35.         if monitor then
  36.             monitor.clear()
  37.             monitor.setCursorPos(1,1)
  38.             monitor.write("OPERATE SEQUENCE")
  39.         end
  40.         print("OPERATE sequence initiated!")
  41.         sleep(1)
  42.         modem.transmit(43, 43, "OPERATE")
  43.         while true do
  44.             local event, side, channel, replyChannel, message, distance = os.pullEvent("modem_message")
  45.             if channel == 43 then
  46.                 local identifier, action = message:match("^(%w+)%s+(%d+)$")
  47.                 if action == "OPERATIVE" then
  48.                     if monitor then
  49.                         local cx, cy = monitor.getCursorPos()
  50.                         monitor.setCursorPos(cx + 1, cy + 1)
  51.                         monitor.write(identifier .. " IS OPERATIVE")
  52.                     end
  53.                     print(identifier .. " IS OPERATIVE")
  54.                 end
  55.             end
  56.             sleep(0.5)
  57.         end
  58.     end
  59. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement