Advertisement
Whiskee

CC Wireless Modem Channel Scanner

Jan 9th, 2021 (edited)
661
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local ogPrint = print
  2. function print(...)
  3.     term.clearLine()
  4.     ogPrint(...)
  5. end
  6.  
  7. local args = {...}
  8. local modem = peripheral.find("modem")
  9.  
  10. if (not modem) then return end
  11.  
  12. modem.closeAll()
  13. term.clear()
  14. term.setCursorPos(1,1)
  15.  
  16. local modemLimit = 128
  17. local bandLimit = 256
  18.  
  19. local band = tonumber(args[1]) or 1
  20. local startRange = modemLimit * (band - 1)
  21. local endRange = modemLimit * band
  22.  
  23. local i = startRange
  24. while i < endRange do
  25.  modem.open(i)
  26.  i = i + 1
  27. end
  28.  
  29. while true do
  30.     term.setCursorPos(1,1)
  31.     print("Band: "..band)
  32.     print("Range: "..startRange.." - "..endRange - 1)
  33.     local event, modemSide, senderChannel,
  34.         replyChannel, message, senderDistance = os.pullEvent()
  35.  
  36.     if (event == "modem_message") then
  37.         term.clear()
  38.         print("Received a message from channel: "..senderChannel)
  39.         print("They expect a reply on channel: "..replyChannel)
  40.         print("The message was: "..message)
  41.     elseif (event == "key") then
  42.         if (modemSide == keys.down or modemSide == keys.up) then
  43.             if (modemSide == keys.up and band < bandLimit) then
  44.                 band = band + 1
  45.             elseif (band > 1) then
  46.                 band = band - 1
  47.             end
  48.            
  49.             local x = 0
  50.             modem.closeAll()
  51.             startRange = modemLimit * (band - 1)
  52.             endRange = (modemLimit * band)
  53.             x = startRange
  54.             while x < endRange do
  55.                 modem.open(x)
  56.                 x = x + 1
  57.             end
  58.         end
  59.     end
  60. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement