Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- turtle_remote.lua
- os.loadAPI("flex.lua")
- local modem_channel = 8464 -- Use the same channel as your receive_pocket.lua
- local turtle_channel = 6464 -- The channel the turtle is listening on (from flex_options.cfg or default)
- local modem
- local p = flex.getPeripheral("modem")
- if #p > 0 then
- modem = peripheral.wrap(p[1])
- modem.open(modem_channel)
- else
- print("Please attach a wireless or ender modem")
- sleep(2)
- return
- end
- local turtle_status = {} -- Table to store the last received status from the turtle
- local function displayStatus()
- term.clear()
- term.setCursorPos(1, 1)
- print("--- Turtle Status ---")
- if next(turtle_status) == nil then
- print("Waiting for status update...")
- else
- print("Fuel: " .. tostring(turtle_status.fuel))
- print("Position: X=" .. tostring(turtle_status.position.x) .. ", Y=" .. tostring(turtle_status.position.y) .. ", Z=" .. tostring(turtle_status.position.z))
- print("Mining: " .. tostring(turtle_status.is_mining))
- print("Estimated Time: " .. tostring(turtle_status.estimated_time))
- print("\nInventory:")
- if next(turtle_status.inventory) == nil then
- print(" Empty")
- else
- for slot, item in pairs(turtle_status.inventory) do
- print(" Slot " .. tostring(slot) .. ": " .. item.name .. " (" .. tostring(item.count) .. ")")
- end
- end
- end
- print("\n--- Commands ---")
- print("Press S to Refresh Status")
- print("Press U to Force Unload")
- print("Press Q to Quit")
- end
- local function sendCommand(command_type)
- local command_message = {
- type = "command",
- command = command_type
- }
- modem.transmit(modem_channel, turtle_channel, command_message)
- end
- -- Initial status request
- sendCommand("status_request")
- while true do
- displayStatus()
- local event, param = os.pullEvent("key" or "modem_message")
- if event == "key" then
- local key_code = param
- if key_code == keys.s then
- sendCommand("status_request")
- elseif key_code == keys.u then
- sendCommand("unload_command")
- elseif key_code == keys.q then
- break -- Exit the loop
- end
- elseif event == "modem_message" then
- local modemSide, senderChannel, replyChannel, message, senderDistance = param, select(2, os.pullEvent()), select(3, os.pullEvent()), select(4, os.pullEvent()), select(5, os.pullEvent())
- -- Check if the message is from the expected turtle (optional but recommended)
- -- You might need to send the turtle's ID with its status updates
- if type(message) == "table" and message.type == "status" then
- turtle_status = message
- elseif type(message) == "table" and message.type == "ack" then
- print("\nCommand '" .. message.command .. "' acknowledged.")
- sleep(1) -- Show acknowledgment message briefly
- end
- end
- end
- modem.close(modem_channel)
- term.clear()
- term.setCursorPos(1, 1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement