zahar0401

CC Modem Utility

Jul 11th, 2016
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.24 KB | None | 0 0
  1. local mArgs = {...}
  2. local help = "modem <open/close/status/help>"
  3.  
  4. function autoOpen()
  5.  for _, v in pairs(rs.getSides()) do
  6.   if peripheral.isPresent(v) and peripheral.getType(v) == "modem" then
  7.    if not rednet.isOpen(v) then
  8.     rednet.open(v)
  9.     print("Modem opened on "..v.." side")
  10.    else
  11.     printError("Modem on "..v.." side already open")
  12.    end
  13.   end
  14.  end
  15. end
  16.  
  17. function autoClose()
  18.  for _, v in pairs(rs.getSides()) do
  19.   if peripheral.isPresent(v) and peripheral.getType(v) == "modem" then
  20.    if rednet.isOpen(v) then
  21.     rednet.close(v)
  22.     print("Modem closed on "..v.." side")
  23.    else
  24.     printError("Modem on "..v.." side already closed")
  25.    end
  26.   end
  27.  end
  28. end
  29.  
  30. function list()
  31.  for _, v in pairs(rs.getSides()) do
  32.   if peripheral.isPresent(v) and peripheral.getType(v) == "modem" then
  33.    print("Modem detected on "..v.." side")
  34.    if rednet.isOpen(v) then
  35.     print("Modem is open")
  36.    elseif not rednet.isOpen(v) then
  37.     print("Modem is closed")
  38.    end
  39.   end
  40.  end
  41. end
  42.  
  43. if #mArgs < 1 then
  44.  print(help)
  45. else
  46.  if mArgs[1] == "open" then
  47.   autoOpen()
  48.  elseif mArgs[1] == "close" then
  49.   autoClose()
  50.  elseif mArgs[1] == "status" then
  51.   list()
  52.  elseif mArgs[1] == "help" then
  53.   print(help)
  54.  end
  55. end
Advertisement
Add Comment
Please, Sign In to add comment