MtnMCG

smartmineslave

Jul 21st, 2024 (edited)
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.13 KB | None | 0 0
  1. -- Define the port for communication
  2. local PORT = 2469
  3.  
  4. -- Initialize the modem
  5. local modem = peripheral.find("modem")
  6.  
  7. if not modem then
  8.     print("No modem found. Please attach a modem to this turtle.")
  9.     return
  10. end
  11.  
  12. -- Open the port
  13. modem.open(PORT)
  14.  
  15. -- Function to handle incoming messages
  16. local function handleMessage()
  17.     while true do
  18.         local event, side, channel, replyChannel, message, distance = os.pullEvent("modem_message")
  19.        
  20.         if channel == PORT then
  21.             if message == "start" then
  22.                 print("Received start signal.")
  23.                 os.run("smartmine.lua") -- Adjust the path if necessary
  24.             elseif message == "stop" then
  25.                 print("Received stop signal.")
  26.                 -- Assuming smartmine.lua can handle stopping gracefully
  27.                 -- You might need to implement a stop mechanism
  28.             elseif message == "stats" then
  29.                 local fuelLevel = turtle.getFuelLevel()
  30.                 modem.transmit(PORT, PORT, tostring(fuelLevel))
  31.             end
  32.         end
  33.     end
  34. end
  35.  
  36. -- Start handling messages
  37. handleMessage()
  38.  
Advertisement
Add Comment
Please, Sign In to add comment