Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- TURTLES = {}
- TURTLE_COUNT = 0
- DEPLOYER = 0
- CHEST_X = 0
- CHEST_Z = 0
- function prepare()
- print("How many turtles should connect? (Max 8)")
- TURTLE_COUNT = tonumber(read())
- local currentTurtles = 0
- if TURTLE_COUNT ~= nil then
- local message
- DEPLOYER, message = rednet.receive("minenetfromdeployer", 10000)
- rednet.send(DEPLOYER, TURTLE_COUNT, "minenettodeployer")
- while currentTurtles < TURTLE_COUNT do
- local turtle_id, message = rednet.receive("minenettoserver", 10000)
- rednet.send(turtle_id, "Welcome!", "minenettoclient")
- TURTLES[currentTurtles] = turtle_id
- print("Turtle #" .. turtle_id .. " connected")
- currentTurtles = currentTurtles + 1
- end
- DEPLOYER, message = rednet.receive("minenetfromdeployer", 10000)
- print("How many blocks should the turtles go?")
- local distance = tonumber(read())
- if distance ~= nil then
- for i=0, currentTurtles - 1 do
- rednet.send(TURTLES[i], distance, "minenettoclient")
- end
- return true
- else
- return false
- end
- else
- print("Please enter a valid number")
- return false
- end
- end
- function main()
- rednet.open("right")
- if rednet.isOpen("right") ~= true then
- print("Failed to start modem!")
- return
- end
- local successfulTurtles = 0
- if prepare() == true then
- while successfulTurtles < TURTLE_COUNT do
- local id, message = rednet.receive("minenettoserver")
- if message == "returned" then
- print("Turtle #" .. id .. " has returned to the start")
- successfulTurtles = successfulTurtles + 1
- elseif message == "returning" then
- print("Turtle #" .. id .. " has finished mining and is returning to the start")
- elseif message == "out_of_fuel" then
- print("Turtle #" .. id .. " has ran out of fuel")
- end
- end
- rednet.send(DEPLOYER, "cleanup", "minenettodeployer")
- end
- rednet.close("right")
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement