Advertisement
DabDaddy6223

mine_server

Apr 14th, 2025 (edited)
647
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.18 KB | None | 0 0
  1. TURTLES = {}
  2. TURTLE_COUNT = 0
  3.  
  4. DEPLOYER = 0
  5.  
  6. CHEST_X = 0
  7. CHEST_Z = 0
  8.  
  9. function prepare()
  10.     print("How many turtles should connect? (Max 8)")
  11.  
  12.     TURTLE_COUNT = tonumber(read())
  13.     local currentTurtles = 0
  14.    
  15.     if TURTLE_COUNT ~= nil then
  16.         local message
  17.         DEPLOYER, message = rednet.receive("minenetfromdeployer", 10000)
  18.         rednet.send(DEPLOYER, TURTLE_COUNT, "minenettodeployer")
  19.  
  20.         while currentTurtles < TURTLE_COUNT do
  21.             local turtle_id, message = rednet.receive("minenettoserver", 10000)
  22.             rednet.send(turtle_id, "Welcome!", "minenettoclient")
  23.  
  24.             TURTLES[currentTurtles] = turtle_id
  25.  
  26.             print("Turtle #" .. turtle_id .. " connected")
  27.             currentTurtles = currentTurtles + 1
  28.         end
  29.  
  30.         DEPLOYER, message = rednet.receive("minenetfromdeployer", 10000)
  31.  
  32.         print("How many blocks should the turtles go?")
  33.         local distance = tonumber(read())
  34.         if distance ~= nil then
  35.             for i=0, currentTurtles - 1 do
  36.                 rednet.send(TURTLES[i], distance, "minenettoclient")
  37.             end
  38.  
  39.             return true
  40.         else
  41.             return false
  42.         end
  43.     else
  44.         print("Please enter a valid number")
  45.         return false
  46.     end
  47. end
  48.  
  49. function main()
  50.     rednet.open("right")
  51.     if rednet.isOpen("right") ~= true then
  52.         print("Failed to start modem!")
  53.         return
  54.     end
  55.  
  56.     local successfulTurtles = 0
  57.     if prepare() == true then
  58.         while successfulTurtles < TURTLE_COUNT do
  59.             local id, message = rednet.receive("minenettoserver")
  60.             if message == "returned" then
  61.                 print("Turtle #" .. id .. " has returned to the start")
  62.                 successfulTurtles = successfulTurtles + 1
  63.             elseif message == "returning" then
  64.                 print("Turtle #" .. id .. " has finished mining and is returning to the start")
  65.             elseif message == "out_of_fuel" then
  66.                 print("Turtle #" .. id .. " has ran out of fuel")
  67.             end
  68.         end
  69.         rednet.send(DEPLOYER, "cleanup", "minenettodeployer")
  70.     end
  71.  
  72.     rednet.close("right")
  73. end
  74.  
  75. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement