Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local tArgs = {...}
- local direction = {
- ["forw"] =1;
- ["right"] =2;
- ["back"] =3;
- ["left"] =4;
- }
- local pos = {
- ["x"]=0;
- ["y"]=0;
- }
- dir=direction.forw;
- local lenght
- local width
- local function saveState()
- name = shell.getRunningProgram()
- local file = fs.open(name..".save","w")
- file.writeLine(pos.x)
- file.writeLine(pos.y)
- file.writeLine(dir)
- file.writeLine(lenght)
- file.writeLine(width)
- file.close()
- end
- local function readState()
- name = shell.getRunningProgram()
- if not fs.exists(name..".save") then
- return false
- end
- local file = fs.open(name..".save","r")
- pos.x = tonumber(file.readLine())
- pos.y = tonumber(file.readLine())
- dir = tonumber(file.readLine())
- lenght = tonumber(file.readLine())
- width = tonumber(file.readLine())
- file.close()
- return true
- end
- local function turnRight()
- dir=dir+1
- if dir==5 then dir = direction.forw end
- saveState()
- turtle.turnRight()
- end
- local function turnLeft()
- dir=dir-1
- if dir==0 then dir = direction.left end
- saveState()
- turtle.turnLeft()
- end
- local function forward()
- while true do
- if turtle.detect() then --обнаружен блок, сломать
- if turtle.dig() then
- -- print("detect block")
- else
- print("detect bedrock or unbreaking block")
- return false
- end
- elseif turtle.attack() then -- Впереди нет блока, проверяем есть ли там существо
- print("detect monster or player")
- else -- Передвигаемся вперед
- local ty,tx = pos.y,pos.x
- if dir == direction.forw then
- pos.x=pos.x+1
- elseif dir == direction.right then
- pos.y=pos.y+1
- elseif dir == direction.back then
- pos.x=pos.x-1
- elseif dir == direction.left then
- pos.y=pos.y-1
- end
- saveState()
- print("--")
- print(pos.y)
- if turtle.forward() then
- -- print("it's ok!")
- return true
- else
- -- backup
- if not turtle.detect() then
- print("detect unknowing object")
- end
- pos.y = ty
- pos.x = tx
- saveState()
- print(pos.y)
- os.sleep(0.5)
- end
- end
- end
- end
- local t=turtle
- if tArgs == 0 then
- tArgs[1] = 8
- end
- function refuel()
- t.select(16)
- while t.getFuelLevel()<100 do
- if not turtle.refuel(1) then
- print("Put fuel in slot 16")
- os.sleep(10)
- end
- end
- end
- function cleaninv()
- for i=1,15 do
- t.select(i)
- t.drop()
- end
- t.select(1)
- end
- function suck()
- turnRight()
- t.suck()
- t.suckUp()
- turnLeft()
- t.suck()
- t.suckUp()
- turnLeft()
- t.suck()
- t.suckUp()
- turnRight()
- end
- function main()
- while true do
- for i=1,tArgs[1] do
- suck()
- refuel()
- forward()
- end
- turnRight()
- turnRight()
- for i=1,tArgs[1] do
- suck()
- refuel()
- forward()
- end
- cleaninv()
- turnRight()
- turnRight()
- refuel()
- sleep(120)
- end
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement