Advertisement
TitanChase

newcontrolpanel.lua

Nov 10th, 2016
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.74 KB | None | 0 0
  1. shell.run("clear")
  2.  
  3. local selectedId
  4. local found = false
  5.  
  6. ids = {}
  7. names = {}
  8.  
  9. term.setTextColor(colors.blue)
  10. textutils.slowPrint("===Control Panel System===")
  11. textutils.slowPrint("=====By DiscworldZA=======")
  12.  
  13. term.setTextColor(colors.red)
  14. textutils.slowPrint("Scanning For Computers In Range....")
  15.  
  16. function has_value (tab, val)
  17.     for index, value in ipairs (tab) do
  18.         if value == val then
  19.             return true
  20.         end
  21.     end
  22.  
  23.     return false
  24. end
  25.  
  26. function timer()
  27.     for i=1,5 do
  28.         print(i)
  29.         sleep(1)
  30.     end
  31. end
  32.  
  33. function printComputers()
  34.     term.setTextColor(colors.blue)
  35.     print("ID Name")
  36.     for i=1,#ids do
  37.         print(ids[i] .. "  " .. names[i])
  38.     end
  39. end
  40.  
  41. function searchAll()
  42.     rednet.open("back")
  43.     while true do
  44.         id, message, protocol = rednet.receive("control")
  45.         if not has_value(ids, id) then
  46.             table.insert(ids, id)
  47.             table.insert(names, message)
  48.         end
  49.     end
  50.     rednet.close("back")
  51. end
  52.  
  53. function searchOne()
  54.     while true do
  55.         rednet.open("back")
  56.         id, message, protocol = rednet.receive("control")
  57.         if not has_value(ids, id) then
  58.             table.insert(ids, id)
  59.             table.insert(names, message)
  60.             found = true
  61.             break
  62.         end
  63.         rednet.close("back")
  64.     end
  65. end
  66.  
  67. function menu()
  68.     while true do
  69.         shell.run("clear")
  70.         term.setTextColor(colors.blue)
  71.         print("===Menu===")
  72.         term.setTextColor(colors.green)
  73.         print("1. Start")
  74.         print("2. Stop")
  75.         print("3. Command")
  76.         print("4. Select Computer")
  77.         print("Q. Quit")
  78.         write("Select Command:")
  79.         command = read()
  80.  
  81.         if string.lower(command) == "start" or command == "1" then
  82.             print("Enter Program to Start:")
  83.             program = read()
  84.             shell.run("send " .. selectedId .. " fg " .. program)
  85.         end
  86.  
  87.         if string.lower(command) == "stop" or command == "2" then
  88.             print("Enter Program to Stop:")
  89.             program = read()
  90.             shell.run("send " .. selectedId .. " exit " .. program)
  91.         end
  92.  
  93.         if string.lower(command) == "command" or command == "3" then
  94.             print("Enter Command:")
  95.             program = read()
  96.             shell.run("send " .. selectedId .. " " .. program)
  97.         end
  98.  
  99.         if string.lower(command) == "select" or string.lower(command) == "4" then
  100.             select()
  101.         end
  102.  
  103.         if string.lower(command) == "quit" or string.lower(command) == "q" then
  104.             error()
  105.         end
  106.     end
  107. end
  108.  
  109. function select()
  110.     printComputers()
  111.     term.setTextColor(colors.white)
  112.     write("Select Computer: ")
  113.     selectedId = read()
  114.     while not has_value(ids, tonumber(selectedId)) do
  115.         print("Invalid Id")
  116.         write("Select Computer: ")
  117.         selectedId = read()
  118.     end
  119.     menu()
  120. end
  121.  
  122. parallel.waitForAny(timer, searchAll)
  123.  
  124. while true do
  125.     parallel.waitForAny(select, searchOne)
  126.     if found then
  127.         term.setTextColor(colors.green)
  128.         print("")
  129.         print("New Computer Found!")
  130.         printComputers()
  131.     end
  132. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement