Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local target = 0
- if(arg[4] == nil) then
- print("not enough arg")
- return
- end
- local weight = tonumber(arg[1])
- local pMode = nil
- local orient = "RIGHT"
- local turntFlag = false
- if(arg[4] == "l") then
- orient = "LEFT"
- turntFlag = true
- elseif (arg[4] == "r") then
- orient = "RIGHT"
- else
- print("not valid orient!")
- return
- end
- if(arg[3] == "ver") then
- pMode = "VER"
- turntFlag = false
- elseif (arg[3] == "hor") then
- pMode = "HOR"
- else
- print("not valid mode!")
- return
- end
- print("input confirm to start work");
- if(io.read() ~= "confirm" ) then
- print("u not confirm!")
- return
- end
- print("start work!")
- local emptyFlag =false
- local bkslot = 2
- local function turtleSelfCheck()
- -- check fuel
- if(turtle.getFuelLevel() < 100) then
- turtle.select(1)
- turtle.refuel(1)
- end
- -- check space
- turtle.select(bkslot)
- if(emptyFlag == false) then
- while (turtle.getItemCount() == 0) do
- bkslot = bkslot + 1
- if(turtle.getItemCount(2) ~= 0) then
- bkslot = 2
- break
- end
- if(bkslot > 16) then
- os.shutdown()
- end
- turtle.select(bkslot)
- end
- end
- end
- local function turtleMove(edgeFlag)
- if(pMode == "HOR") then
- if(edgeFlag) then
- if(turntFlag == false) then
- turtle.turnRight()
- turtle.forward()
- turtle.turnRight()
- else
- turtle.turnLeft()
- turtle.forward()
- turtle.turnLeft()
- end
- turntFlag = not turntFlag
- else
- turtle.forward()
- end
- elseif (pMode == "VER") then
- if(turntFlag == false) then
- if(edgeFlag) then
- if(orient == "RIGHT") then
- turtle.turnRight()
- turtle.forward()
- turtle.turnLeft()
- turntFlag = not turntFlag
- else
- turtle.turnLeft()
- turtle.forward()
- turtle.turnRight()
- turntFlag = not turntFlag
- end
- else
- turtle.up()
- end
- else
- if(edgeFlag) then
- if(orient == "RIGHT") then
- turtle.turnRight()
- turtle.forward()
- turtle.turnLeft()
- turntFlag = not turntFlag
- else
- turtle.turnLeft()
- turtle.forward()
- turtle.turnRight()
- turntFlag = not turntFlag
- end
- else
- turtle.down()
- end
- end
- end
- end
- local eFlag = false
- while true do
- local count = 0
- if(weight < 1) then
- break
- end
- while true do
- -- self check
- turtleSelfCheck()
- -- place
- if(pMode == "HOR") then
- turtle.placeDown()
- elseif(pMode == "VER") then
- turtle.place()
- end
- turtle.up()
- -- move
- if(turtle.detect()) then
- if(orient == "RIGHT") then
- turtle.turnRight()
- turtle.forward()
- turtle.turnLeft()
- else
- turtle.turnLeft()
- turtle.forward()
- turtle.turnRight()
- end
- break
- end
- end
- while true do
- -- self check
- turtleSelfCheck()
- -- place
- if(pMode == "HOR") then
- turtle.placeDown()
- elseif(pMode == "VER") then
- turtle.place()
- end
- --move
- if(turtle.detectDown()) then
- if(orient == "RIGHT") then
- turtle.turnRight()
- turtle.forward()
- turtle.turnLeft()
- else
- turtle.turnLeft()
- turtle.forward()
- turtle.turnRight()
- end
- break
- else
- turtle.down()
- end
- end
- weight = weight - 1
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement