Advertisement
Corbinhol

ComputerCraft Quarry Turtle

Sep 12th, 2022 (edited)
754
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.84 KB | None | 0 0
  1. term.clear();
  2. term.setCursorPos(1,1)
  3. print("Turtle Mining Client")
  4. print("Starting...");
  5. print("Setting Up Modem");
  6. local run = false;
  7.  
  8. local hasModem = false;
  9. local modemSide;
  10. local modemProtocol = "mining"
  11. local modemHostname;
  12.  
  13. if peripheral.getType("right") == "modem" then hasModem = true; modemSide = "right";
  14. elseif peripheral.getType("left") == "modem" then hasModem= true; modemSide = "left";
  15. elseif peripheral.getType("front") == "modem" then hasModem= true; modemSide = "front";
  16. elseif peripheral.getType("back") == "modem" then hasModem= true; modemSide = "back";
  17. elseif peripheral.getType("top") == "modem" then hasModem= true; modemSide = "top";
  18. elseif peripheral.getType("bottom") == "modem" then hasModem= true; modemSide = "bottom";
  19. else term.setTextColor(colors.red); print("Error: No Modem Found! Please ensure that a modem is connected to the turtle."); term.setTextColor(colors.white); os.exit()
  20. end
  21.  
  22. rednet.open(modemSide);
  23. for i=1, 25, 1 do
  24.     rednet.unhost(modemProtocol, "MiningTurtle" .. i) --Ensures that turtle does not already have this hostname.
  25.     local checkForTurtle = rednet.lookup(modemProtocol, "MiningTurtle" .. i);
  26.     if checkForTurtle == nil then modemHostname = "MiningTurtle" .. i; rednet.host(modemProtocol, "MiningTurtle" .. i); run = true; break; end
  27. end
  28. if run == false then
  29.     term.setTextColor(colors.red);
  30.     print("There Seems to be no slot available...Exiting");
  31.     term.setTextColor(colors.white);
  32.     os.exit();
  33. else
  34.     term.setTextColor(colors.green);
  35.     print("Set hostname to " .. modemHostname);
  36.     term.setTextColor(colors.white);
  37. end
  38.  
  39. while true do
  40.     sleep(0)
  41.     local event, key = os.pullEvent("key") -- limit os.pullEvent to the 'key' event
  42.     if key == keys.space then break; end
  43. end
  44.  
  45.  
  46.  
  47. --Ending Program
  48. print("Exiting Program...Please do not turn off system.\n")
  49.  
  50.  
  51.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement