legg0028

secret_door_control

Aug 1st, 2021 (edited)
1,042
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local speaker = peripheral.wrap("front")
  2. local modem = peripheral.wrap("left")
  3. modem.open(00003)
  4.  
  5. local wmodem = peripheral.wrap("right")
  6. wmodem.open(00004)
  7.  
  8. local vmodem = peripheral.wrap("back")
  9. vmodem.open(00005)
  10.  
  11. local code1 = 0
  12. local code2 = 0
  13. local code3 = 0
  14. local reset = 1
  15. local outMsg = "0"
  16.  
  17. term.clear()
  18. term.setCursorPos(1,1)
  19. print("Waiting for first message")
  20.  
  21. while true do
  22.     if reset == 0 then
  23.         event, modemSide, senderChannel, replyChannel, message, senderDistance = os.pullEvent("modem_message")
  24.      
  25.         if senderChannel == 3 then
  26.             if code1 == 0 and message == "1" then
  27.                 outMsg = "s1"
  28.                 wmodem.transmit(00004,00004,outMsg)
  29.                 code1 = 1
  30.  
  31.                 term.clear()
  32.                 term.setCursorPos(1,1)
  33.                 print("Message received: "..message)
  34.                 print("Channel: "..senderChannel)
  35.                 print("Message sent: "..outMsg)
  36.                 print("code1: "..code1)
  37.                 print("code2: "..code2)
  38.                 print("code3: "..code3)
  39.             elseif code1 == 1 and message == "2" then
  40.                 outMsg = "s2"
  41.                 wmodem.transmit(00004,00004,outMsg)
  42.                 code2 = 1
  43.  
  44.                 term.clear()
  45.                 term.setCursorPos(1,1)
  46.                 print("Message received: "..message)
  47.                 print("Channel: "..senderChannel)
  48.                 print("Message sent: "..outMsg)
  49.                 print("code1: "..code1)
  50.                 print("code2: "..code2)
  51.                 print("code3: "..code3)
  52.             elseif code2 == 1 and message == "3" then
  53.                 outMsg = "s3"
  54.                 wmodem.transmit(00004,00004,outMsg)
  55.                 code3 = 1
  56.  
  57.                 term.clear()
  58.                 term.setCursorPos(1,1)
  59.                 print("Message received: "..message)
  60.                 print("Channel: "..senderChannel)
  61.                 print("Message sent: "..outMsg)
  62.                 print("code1: "..code1)
  63.                 print("code2: "..code2)
  64.                 print("code3: "..code3)
  65.                 speaker.playSound("astralsorcery:perk_unseal")
  66.                 reset = 1
  67.                 sleep(1)
  68.                 vmodem.transmit(00005,00005,"open")
  69.             else
  70.                 reset = 1
  71.             end
  72.         end
  73.     else
  74.         outMsg = "serror"
  75.         wmodem.transmit(00004,00004,outMsg)
  76.  
  77.         code1 = 0
  78.         code2 = 0
  79.         code3 = 0
  80.  
  81.         print("Waiting for message")
  82.         print("Message sent: "..outMsg)
  83.         term.clear()
  84.         term.setCursorPos(1,1)
  85.         print("code1: "..code1)
  86.         print("code2: "..code2)
  87.         print("code3: "..code3)
  88.  
  89.         reset = 0
  90.     end
  91.     sleep(0.1)
  92. end
RAW Paste Data