Advertisement
Tatantyler

Repair Drone Controller

Nov 25th, 2012
438
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.70 KB | None | 0 0
  1. local repairDrone = -1
  2. local status = {}
  3.  
  4. term.setCursorPos(1,1)
  5. term.clear()
  6.  
  7. print("Repair Drone Command Terminal V1.3")
  8. print("(C) 1989 KillaVanilla Industries")
  9. print("Subcomponents initalizing...")
  10. textutils.slowWrite("Checking: Redstone-Based Communications...")
  11. os.sleep(1)
  12. local modems = 0
  13. for i,v in ipairs(rs.getSides()) do
  14.     if peripheral.getType(v) == "modem" then
  15.         rednet.open(v)
  16.         modems = modems+1
  17.     end
  18. end
  19. if modems > 0 then
  20.     term.setTextColor(colors.lime)
  21.     print("good")
  22. else
  23.     term.setTextColor(colors.red)
  24.     print("failed")
  25.     term.setTextColor(colors.white)
  26.     print("System check failed: No modem found.")
  27.     return
  28. end
  29. term.setTextColor(colors.white)
  30. textutils.slowPrint("Enter the ID of the drone you wish to control: ")
  31. textutils.slowWrite(">")
  32. while true do
  33.     local input = tonumber(read())
  34.     if input then
  35.         repairDrone = input
  36.         break
  37.     end
  38. end
  39. term.setTextColor(colors.white)
  40. textutils.slowWrite("Checking: Remote Repair Unit...")
  41. os.sleep(1)
  42. rednet.send(repairDrone, "PING")
  43. local id, msg = rednet.receive(5)
  44. if id == nil then
  45.     term.setTextColor(colors.red)
  46.     print("failed")
  47.     term.setTextColor(colors.white)
  48.     print("System check failed: Could not contact drone.")
  49.     os.reboot()
  50. else
  51.     status = textutils.unserialize(msg)
  52.     term.setTextColor(colors.lime)
  53.     print("good")
  54. end
  55. term.setTextColor(colors.white)
  56. textutils.slowWrite("Checking: Robotics Supply Unit...")
  57. os.sleep(1)
  58. if (status[1] == "unlimited" or status[1] > 0) and (status[2] > 0) then
  59.     term.setTextColor(colors.lime)
  60.     print("good")
  61. else
  62.     term.setTextColor(colors.red)
  63.     print("failed")
  64.     term.setTextColor(colors.white)
  65.     print("System check failed: Not enough materials/fuel.")
  66.     return
  67. end
  68. term.setTextColor(colors.white)
  69. os.sleep(1)
  70. textutils.slowWrite("Checking: Robotics Interpreter Unit...")
  71. os.sleep(1)
  72. term.setTextColor(colors.lime)
  73. print("good")
  74. term.setTextColor(colors.white)
  75. textutils.slowWrite("Checking: Secondary Communications Link...")
  76. os.sleep(1)
  77. term.setTextColor(colors.lime)
  78. print("good")
  79. term.setTextColor(colors.white)
  80. textutils.slowWrite("Beginning communications...")
  81. os.sleep(1)
  82. print("Ready.")
  83. os.sleep(2)
  84. local cmdHistory = {}
  85. while true do
  86.     term.clear()
  87.     term.setCursorPos(1,1)
  88.     print("DRONE CONTROL UNIT:")
  89.     write("Connected to repair drone ")
  90.     term.setTextColor(colors.lime)
  91.     write(repairDrone)
  92.     term.setTextColor(colors.white)
  93.     print(".")
  94.     write("Fuel Level: ")
  95.     term.setTextColor(colors.lime)
  96.     print(status[1])
  97.     term.setTextColor(colors.white)
  98.     write("Materials Level: ")
  99.     term.setTextColor(colors.lime)
  100.     print(status[2])
  101.     term.setTextColor(colors.white)
  102.     write("drone"..repairDrone..">")
  103.     local cmd = read(nil, cmdHistory)
  104.     if string.lower(cmd) == "help" then
  105.         term.clear()
  106.         term.setCursorPos(1,1)
  107.         print("Commands:")
  108.         print("forward - Moves the drone forward 1 meter.")
  109.         print("back - Moves the drone back 1 meter.")
  110.         print("turnleft - Turns the drone to the left.")
  111.         print("turnright - Turns the drone to the right.")
  112.         print("up - Moves the drone up 1 meter.")
  113.         print("down - Moves the drone down 1 meter.")
  114.         print("place - Places materials directly beneath the drone.")
  115.         os.pullEvent("key")
  116.     else
  117.         table.insert(cmdHistory, cmd)
  118.         cmd = string.upper(cmd)
  119.         os.sleep(0.5)
  120.         rednet.send(repairDrone, cmd)
  121.         local id, msg = rednet.receive(5)
  122.         if id ~= nil then
  123.             status = textutils.unserialize(msg)
  124.         else
  125.             printError("Error: Communications timeout.")
  126.             return
  127.         end
  128.         if status[1] ~= "unlimited" then
  129.             if status[1] == 0 then
  130.                 printError("Error: Drone is entering low-fuel mode...")
  131.                 return
  132.             end
  133.         end
  134.         if status[2] == 0 then
  135.             printError("Warning: Drone is out of repair materials!")
  136.         end
  137.         os.sleep(0.5)
  138.     end
  139. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement