Advertisement
QuickMash

Untitled

Jun 22nd, 2024 (edited)
482
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.20 KB | None | 0 0
  1. -- Advanced Computer Program for controlling the Mining Turtle with Remote Console Control and ID Prompt
  2. local computerID
  3. local modem = peripheral.wrap("top")  -- Replace "top" with the side where the modem is attached
  4.  
  5. -- Function to send commands to the turtle
  6. local function sendCommand(command)
  7.     modem.transmit(computerID, computerID, command)  -- Send command to turtle using its ID
  8. end
  9.  
  10. -- Function to execute a console command on the turtle
  11. local function executeConsoleCommand(command)
  12.     modem.transmit(computerID, computerID, command)  -- Send command to turtle using its ID
  13.     local _, _, senderID, message = os.pullEvent("modem_message")
  14.     if senderID == computerID then
  15.         print("Turtle console output:")
  16.         print(message)
  17.     else
  18.         print("Unexpected response received")
  19.     end
  20. end
  21.  
  22. -- Function to prompt user for turtle ID
  23. local function promptForTurtleID()
  24.     term.clear()
  25.     term.setCursorPos(1, 1)
  26.     print("Enter Turtle ID:")
  27.     return tonumber(read())  -- Read user input and convert to number (assuming turtle ID is numeric)
  28. end
  29.  
  30. -- Main function to run the program
  31. local function main()
  32.     computerID = promptForTurtleID()
  33.  
  34.     if not computerID then
  35.         print("Invalid Turtle ID entered. Exiting program.")
  36.         return
  37.     end
  38.  
  39.     while true do
  40.         term.clear()
  41.         term.setCursorPos(1, 1)
  42.         print("=== Mining Turtle Remote Control Panel ===")
  43.         print("[1] Mine Chunk")
  44.         print("[2] Return")
  45.         print("[3] Inventory")
  46.         print("[4] Refuel All")
  47.         print("[5] Shutdown Turtle")
  48.         print("[Q] Quit")
  49.  
  50.         local _, key = os.pullEvent("key")
  51.         if key == keys.one then
  52.             sendCommand("mine_chunk")
  53.         elseif key == keys.two then
  54.             sendCommand("return")
  55.         elseif key == keys.three then
  56.             sendCommand("inventory")
  57.         elseif key == keys.four then
  58.             executeConsoleCommand("refuel all")
  59.         elseif key == keys.five then
  60.             sendCommand("shutdown")
  61.             break
  62.         elseif key == keys.q or key == keys.Q then
  63.             break  -- Quit the program
  64.         end
  65.     end
  66. end
  67.  
  68. -- Run the main function
  69. main()
  70.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement