Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- shell.run("clear")
- local selectedId
- local found = false
- ids = {}
- names = {}
- term.setTextColor(colors.blue)
- textutils.slowPrint("===Control Panel System===")
- textutils.slowPrint("=====By DiscworldZA=======")
- term.setTextColor(colors.red)
- textutils.slowPrint("Scanning For Computers In Range....")
- function has_value (tab, val)
- for index, value in ipairs (tab) do
- if value == val then
- return true
- end
- end
- return false
- end
- function timer()
- for i=1,5 do
- print(i)
- sleep(1)
- end
- end
- function printComputers()
- term.setTextColor(colors.blue)
- print("ID Name")
- for i=1,#ids do
- print(ids[i] .. " " .. names[i])
- end
- end
- function searchAll()
- rednet.open("back")
- while true do
- id, message, protocol = rednet.receive("control")
- if not has_value(ids, id) then
- table.insert(ids, id)
- table.insert(names, message)
- end
- end
- rednet.close("back")
- end
- function searchOne()
- while true do
- rednet.open("back")
- id, message, protocol = rednet.receive("control")
- if not has_value(ids, id) then
- table.insert(ids, id)
- table.insert(names, message)
- found = true
- break
- end
- rednet.close("back")
- end
- end
- function menu()
- while true do
- shell.run("clear")
- term.setTextColor(colors.blue)
- print("===Menu===")
- term.setTextColor(colors.green)
- print("1. Start")
- print("2. Stop")
- print("3. Command")
- print("4. Select Computer")
- print("Q. Quit")
- write("Select Command:")
- command = read()
- if string.lower(command) == "start" or command == "1" then
- print("Enter Program to Start:")
- program = read()
- shell.run("send " .. selectedId .. " fg " .. program)
- end
- if string.lower(command) == "stop" or command == "2" then
- print("Enter Program to Stop:")
- program = read()
- shell.run("send " .. selectedId .. " exit " .. program)
- end
- if string.lower(command) == "command" or command == "3" then
- print("Enter Command:")
- program = read()
- shell.run("send " .. selectedId .. " " .. program)
- end
- if string.lower(command) == "select" or string.lower(command) == "4" then
- select()
- end
- if string.lower(command) == "quit" or string.lower(command) == "q" then
- error()
- end
- end
- end
- function select()
- printComputers()
- term.setTextColor(colors.white)
- write("Select Computer: ")
- selectedId = read()
- while not has_value(ids, tonumber(selectedId)) do
- print("Invalid Id")
- write("Select Computer: ")
- selectedId = read()
- end
- menu()
- end
- parallel.waitForAny(timer, searchAll)
- while true do
- parallel.waitForAny(select, searchOne)
- if found then
- term.setTextColor(colors.green)
- print("")
- print("New Computer Found!")
- printComputers()
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement