Posted 01 May 2012 - 12:35 PM
Spoiler
IDs = {31,32,15}
Turtles = 2
Roof = 3
Height = 1
rednet.open("right")
shell.run("clear")
print("Press M to mine")
Roof = Roof-1
function compare()
if turtle.getItemCount(9) ~= 0 then
shell.run("clear")
print("Need to empty slot number 9!")
repeat
sleep(1)
until turtle.getItemCount(9) == 0
end
for n=1,3 do
turtle.select(n)
if turtle.compare() then
turtle.select(1)
return true
end
end
turtle.select(9)
if turtle.compare() then
turtle.select(1)
return true
end
return false
end
function Mine()
if Status ~= "Stuck" then
shell.run("clear")
print("Mining")
Times = 0
if Height == 1 then
Dir = "turtle.up()"
else
Dir = "turtle.down()"
end
for n=1,Roof do
if compare() then
turtle.dig()
if loadstring("return "..Dir)() then
if Dir == "turtle.up()" then
Height = Height+1
else
Height = Height-1
if Height > 1 then
turtle.digDown()
end
end
end
else
prepare()
break
end
end
if Status ~= "Stuck" then
if compare() then
turtle.dig()
else
prepare()
end
if Height == 1 then
turtle.select(4)
turtle.placeDown()
turtle.select(1)
end
Check = os.startTimer(0.1)
end
end
end
function prepare()
shell.run("clear")
print("Waiting for you to press B so we can return to work")
Status = "Stuck"
while Height < Roof+1 do
turtle.up()
Height = Height+1
end
turtle.back()
turtle.back()
Check = os.startTimer(0)
Prepare = os.startTimer(1)
end
Times = 0
Status = "idle"
Comps = {}
function checkID(id)
for n=1,#IDs do
if IDs[n] == id then
return true
end
end
return false
end
while true do
event,param1,param2 = os.pullEvent()
if event == "rednet_message" then
if checkID(param1) then
if param2 == "Checked In" and Status == "Mining" then
if Comps[param1] == nil then
Comps[param1] = "Hello"
Times = Times+1
end
if Times == Turtles then
rednet.send(ID, "Checked In")
rednet.send(ID1, "Checked In")
Times = 0
Comps = {}
if Height == 1 then
turtle.select(4)
turtle.placeDown()
turtle.select(1)
end
if turtle.forward() then
Mine()
Check = os.startTimer(0.1)
else
repeat
if Height == 1 then
turtle.select(4)
turtle.placeDown()
turtle.select(1)
end
turtle.dig()
sleep(0.1)
until turtle.forward()
Mine()
end
end
elseif param2 == "Mine" then
Status = "Mining"
shell.run("clear")
print("Mining")
Mine()
Check = os.startTimer(0.1)
elseif param2 == "Prepare" and Status ~= "Stuck" then
prepare()
end
end
elseif event == "timer" and param1 == Check and Times < Turtles and Status == "Mining" then
rednet.send(ID, "Checked In")
rednet.send(ID1, "Checked In")
Check = os.startTimer(0.1)
elseif event == "timer" and param1 == Prepare then
rednet.send(ID, "Prepare")
rednet.send(ID1, "Prepare")
Prepare = os.startTimer(1)
elseif event == "char" then
if param1 == "m" then
if Status == "idle" then
rednet.send(ID, "Mine")
rednet.send(ID1, "Mine")
Status = "Mining"
Mine()
else
Status = "idle"
end
elseif param1 == "b" and Status == "Stuck" then
turtle.forward()
turtle.forward()
rednet.send(ID, "Mine")
rednet.send(ID1, "Mine")
Status = "Mining"
shell.run("clear")
print("Mining")
Mine()
end
end
end
This mines a tunnel at the height defined in "roof"
Type in the ID's of the turtles you want each one to look after.
Then you want to have the amount of turtles it looks after.
In this case I have 3 turtles. It has to look after 2 other of its turtle mates.
The turtle this runs on has the id of 31. I didnt want to edit the ID's so I can just copy/paste it to each turtle.
Place 3 objects you do not care about it mining in the first 3 slots.
Place cobble or something in the 4th. This is used to fill any holes in the ground.
The 9th is used to check if there is air.
So this must be empty.
The turtles should stop when full.
There should not be bugs.
When it encounters a block it isn't ordered to mine. Aka. the 3 slots. It will raise to roof height and wait for you to take care of it.
Then you go into the turtle and press "b" to resume.
The turtles will wait for each other so they don't get spread/split up