SHARE
TWEET

Drill Monitor

ignjat2 Apr 20th, 2019 (edited) 103 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function DrillMonitor()
  2.   monitor = peripheral.wrap("monitor_1")
  3.   monitor.setTextScale(0.5)
  4.   rednet.broadcast("Status", "Drill"..Drill1ID)
  5.   id, status = rednet.receive("Drill"..Drill1ID, 1)
  6.   if status == "On" then
  7.     term.redirect(monitor)
  8.     term.setTextColor(colors.green)
  9.     term.redirect(monitor)
  10.     print("\nComputer 1: active")
  11.     term.redirect(monitor)
  12.     print("First Laser Drill status: active")
  13.   elseif status == "Off" then
  14.     term.redirect(monitor)
  15.     term.setTextColor(colors.green)
  16.     term.redirect(monitor)
  17.     print("\nComputer 1: active")
  18.     term.setTextColor(colors.red)
  19.     term.redirect(monitor)
  20.     print("First Laser Drill status: inactive")
  21.   else
  22.     term.redirect(monitor)
  23.     term.setTextColor(colors.red)
  24.     term.redirect(monitor)
  25.     print("\nComputer 1: inactive")
  26.     term.setTextColor(colors.gray)
  27.     term.redirect(monitor)
  28.     print("First Laser Drill status: unknown")
  29.   end
  30.   rednet.broadcast("Status", "Drill"..Drill2ID)
  31.   id, status = rednet.receive("Drill"..Drill2ID, 1)
  32.   if status == "On" then
  33.     term.redirect(monitor)
  34.     term.setTextColor(colors.green)
  35.     term.redirect(monitor)
  36.     print("\nComputer 2: active")
  37.     term.redirect(monitor)
  38.     print("Second Laser Drill status: active")
  39.   elseif status == "Off" then
  40.     term.redirect(monitor)
  41.     term.setTextColor(colors.green)
  42.     term.redirect(monitor)
  43.     print("\nComputer 2: active")
  44.     term.setTextColor(colors.red)
  45.     term.redirect(monitor)
  46.     print("Second Laser Drill status: inactive")
  47.   else
  48.     term.redirect(monitor)
  49.     term.setTextColor(colors.red)
  50.     term.redirect(monitor)
  51.     print("\nComputer 2: inactive")
  52.     term.setTextColor(colors.gray)
  53.     term.redirect(monitor)
  54.     print("Second Laser Drill status: unknown")
  55.   end
  56.   rednet.broadcast("Status", "Drill"..Drill3ID)
  57.   id, status = rednet.receive("Drill"..Drill3ID, 1)
  58.   if status == "On" then
  59.     term.redirect(monitor)
  60.     term.setTextColor(colors.green)
  61.     term.redirect(monitor)
  62.     print("\nComputer 3: active")
  63.     term.redirect(monitor)
  64.     print("Third Laser Drill status: active")
  65.   elseif status == "Off" then
  66.     term.redirect(monitor)
  67.     term.setTextColor(colors.green)
  68.     term.redirect(monitor)
  69.     print("\nComputer 3: active")
  70.     term.setTextColor(colors.red)
  71.     term.redirect(monitor)
  72.     print("Third Laser Drill status: inactive")
  73.   else
  74.     term.redirect(monitor)
  75.     term.setTextColor(colors.red)
  76.     term.redirect(monitor)
  77.     print("\nComputer 3: inactive")
  78.     term.setTextColor(colors.gray)
  79.     term.redirect(monitor)
  80.     print("Third Laser Drill status: unknown")
  81.   end
  82.   rednet.broadcast("Status", "Drill"..Drill4ID)
  83.   id, status = rednet.receive("Drill"..Drill4ID, 1)
  84.   if status == "On" then
  85.     term.redirect(monitor)
  86.     term.setTextColor(colors.green)
  87.     term.redirect(monitor)
  88.     print("\nComputer 4: active")
  89.     term.redirect(monitor)
  90.     print("Fourth Laser Drill status: active")
  91.   elseif status == "Off" then
  92.     term.redirect(monitor)
  93.     term.setTextColor(colors.green)
  94.     term.redirect(monitor)
  95.     print("\nComputer 4: active")
  96.     term.setTextColor(colors.red)
  97.     term.redirect(monitor)
  98.     print("Fourth Laser Drill status: inactive")
  99.   else
  100.     term.redirect(monitor)
  101.     term.setTextColor(colors.red)
  102.     term.redirect(monitor)
  103.     print("\nComputer 4: inactive")
  104.     term.setTextColor(colors.gray)
  105.     term.redirect(monitor)
  106.     print("Fourth Laser Drill status: unknown")
  107.   end
  108.   rednet.broadcast("Status", "Drill"..Drill5ID)
  109.   id, status = rednet.receive("Drill"..Drill5ID, 1)
  110.   if status == "On" then
  111.     term.redirect(monitor)
  112.     term.setTextColor(colors.green)
  113.     term.redirect(monitor)
  114.     print("\nComputer 5: active")
  115.     term.redirect(monitor)
  116.     print("Fifth Laser Drill status: active")
  117.   elseif status == "Off" then
  118.     term.redirect(monitor)
  119.     term.setTextColor(colors.green)
  120.     term.redirect(monitor)
  121.     print("\nComputer 5: active")
  122.     term.setTextColor(colors.red)
  123.     term.redirect(monitor)
  124.     print("Fifth Laser Drill status: inactive")
  125.   else
  126.     term.redirect(monitor)
  127.     term.setTextColor(colors.red)
  128.     print("\nComputer 5: inactive")
  129.     term.setTextColor(colors.gray)
  130.     print("Fifth Laser Drill status: unknown")
  131.   end
  132.   rednet.broadcast("Status", "Drill"..Drill6ID)
  133.   id, status = rednet.receive("Drill"..Drill6ID, 1)
  134.   if status == "On" then
  135.     term.redirect(monitor)
  136.     term.setTextColor(colors.green)
  137.     term.redirect(monitor)
  138.     print("\nComputer 6: active")
  139.     term.redirect(monitor)
  140.     print("Sixth Laser Drill status: active")
  141.   elseif status == "Off" then
  142.     term.redirect(monitor)
  143.     term.setTextColor(colors.green)
  144.     term.redirect(monitor)
  145.     print("\nComputer 6: active")
  146.     term.setTextColor(colors.red)
  147.     term.redirect(monitor)
  148.     print("Sixth Laser Drill status: inactive")
  149.   else
  150.     term.redirect(monitor)
  151.     term.setTextColor(colors.red)
  152.     term.redirect(monitor)
  153.     print("\nComputer 6: inactive")
  154.     term.setTextColor(colors.gray)
  155.     term.redirect(monitor)
  156.     print("Sixth Laser Drill status: unknown")
  157.   end
  158.   rednet.broadcast("Status", "Drill"..Drill7ID)
  159.   id, status = rednet.receive("Drill"..Drill7ID, 1)
  160.   if status == "On" then
  161.     term.redirect(monitor)
  162.     term.setTextColor(colors.green)
  163.     term.redirect(monitor)
  164.     print("\nComputer 7: active")
  165.     term.redirect(monitor)
  166.     print("Seventh Laser Drill status: active")
  167.   elseif status == "Off" then
  168.     term.redirect(monitor)
  169.     term.setTextColor(colors.green)
  170.     term.redirect(monitor)
  171.     print("\nComputer 7: active")
  172.     term.setTextColor(colors.red)
  173.     term.redirect(monitor)
  174.     print("Seventh Laser Drill status: inactive")
  175.   else
  176.     term.redirect(monitor)
  177.     term.setTextColor(colors.red)
  178.     term.redirect(monitor)
  179.     print("\nComputer 7: inactive")
  180.     term.setTextColor(colors.gray)
  181.     term.redirect(monitor)
  182.     print("Seventh Laser Drill status: unknown")
  183.   end
  184.   rednet.broadcast("Status", "Drill"..Drill8ID)
  185.   id, status = rednet.receive("Drill"..Drill8ID, 1)
  186.   if status == "On" then
  187.     term.redirect(monitor)
  188.     term.setTextColor(colors.green)
  189.     term.redirect(monitor)
  190.     print("\nComputer 8: active")
  191.     term.redirect(monitor)
  192.     print("Eighth Laser Drill status: active")
  193.   elseif status == "Off" then
  194.     term.redirect(monitor)
  195.     term.setTextColor(colors.green)
  196.     term.redirect(monitor)
  197.     print("\nComputer 8: active")
  198.     term.setTextColor(colors.red)
  199.     term.redirect(monitor)
  200.     print("Eighth Laser Drill status: inactive")
  201.   else
  202.     term.redirect(monitor)
  203.     term.setTextColor(colors.red)
  204.     term.redirect(monitor)
  205.     print("\nComputer 8: inactive")
  206.     term.setTextColor(colors.gray)
  207.     term.redirect(monitor)
  208.     print("Eighth Laser Drill status: unknown")
  209.   end
  210.   os.sleep(1)
  211.   term.redirect(monitor)
  212.   shell.run("clear")
  213.   DrillMonitor(true)
  214. end
  215.  
  216. function Startup()
  217.   if fs.exists("DrillIDs") then
  218.     DataInit(true)
  219.     if Drill1ID == nil then
  220.       term.setTextColor(colors.red)
  221.       print("\nInvalid drill IDs found\n")
  222.       shell.run("delete DrillMonitor")
  223.       print("Exiting program")
  224.       os.sleep(2)
  225.     else
  226.       Warning(true)
  227.     end
  228.   else
  229.     os.sleep(1)
  230.     term.setTextColor(colors.red)
  231.     print("\nNo drill IDs found\n")
  232.     print("Exiting program")
  233.     term.setTextColor(colors.white)
  234.     shell.run("delete DrillMonitor")
  235.     os.sleep(2)
  236.   end
  237. end
  238.  
  239. function DataInit()
  240.   file = fs.open("DrillIDs/".."Data", "r")
  241.   DrillData = {}
  242.   Data = file.readLine()
  243.   repeat
  244.     table.insert(DrillData, Data)
  245.     Data = file.readLine()
  246.   until Data == nil
  247.   file.close()
  248.   Drill1ID = DrillData[1]
  249.   Drill2ID = DrillData[2]
  250.   Drill3ID = DrillData[3]
  251.   Drill4ID = DrillData[4]
  252.   Drill5ID = DrillData[5]
  253.   Drill6ID = DrillData[6]
  254.   Drill7ID = DrillData[7]
  255.   Drill8ID = DrillData[8]
  256. end
  257.  
  258. function Warning()
  259.   Center("Monitoring drills\n\n\n")
  260.   term.setTextColor(colors.red)
  261.   Center("[Warning]\n")
  262.   print("Monitoring may interfere with accessibility to the other computers")
  263.   term.setTextColor(colors.white)
  264.   DrillMonitor(true)
  265. end
  266.  
  267. function Center(text)
  268.   x, y = term.getSize()
  269.   x2, y2 = term.getCursorPos()
  270.   term.setCursorPos(math.ceil((x / 2) - (text:len() / 2)), y2)
  271.   write(text)
  272. end
  273.  
  274. rednet.open("top")
  275. os.sleep(0.2)
  276. Startup(true)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top