Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local tArgs = {...}
- trans={}
- trans[0]="north"
- trans[1]="west"
- trans[2]="south"
- trans[3]="east"
- if #tArgs ~= 9 then
- print("Not enough Arguments")
- error()
- end
- --[[if tArgs[4] ~= "north" then
- elseif tArgs[4] ~= "east" then
- elseif tArgs[4] ~= "south" then
- elseif tArgs[4] ~= "west" then
- for k,v in pairs(trans) do
- if tArgs[4] == k
- then tArgs[4] = v
- end
- end
- else
- print("Argument 4 must be = north, east, south or west.")
- error()
- end]]--
- for k,v in pairs(trans) do
- if tArgs[4] == v
- then tArgs[4] = k
- end
- end
- local cDir = tonumber(tArgs[4])
- local cX = tonumber(tArgs[1])
- local cY = tonumber(tArgs[2])
- local cZ = tonumber(tArgs[3])
- function turnRight()
- if cDir == 0 then
- cDir = 3
- elseif cDir == 3 then
- cDir = 2
- elseif cDir == 2 then
- cDir = 1
- elseif cDir == 1 then
- cDir = 0
- else
- print("TurnrightError!!")
- return nil
- end
- turtle.turnRight()
- end
- function turnLeft()
- if cDir == 0 then
- cDir = 1
- elseif cDir == 3 then
- cDir = 0
- elseif cDir == 2 then
- cDir = 3
- elseif cDir == 1 then
- cDir = 2
- else
- print("TurnLeftError!!")
- return nil
- end
- turtle.turnLeft()
- end
- function turnTo(dir)
- if cDir ~= dir then
- repeat
- turnRight()
- until cDir == dir
- end
- end
- function moveForward()
- if cDir == 0 then
- cZ = cZ-1
- elseif cDir == 3 then
- cX = cX+1
- elseif cDir == 2 then
- cZ = cZ+1
- elseif cDir == 1 then
- cX = cX-1
- else
- print("forwardError!!")
- return nil
- end
- while not turtle.forward() do
- turtle.dig()
- end
- end
- function moveUp()
- cY = cY+1
- while not turtle.up() do
- turtle.digUp()
- end
- end
- function moveDown()
- cY = cY-1
- while not turtle.down() do
- turtle.digDown()
- end
- end
- function moveToX(x)
- if cX < x then
- turnTo(3)
- repeat
- moveForward()
- until cX == x
- elseif cX > x then
- turnTo(1)
- repeat
- moveForward()
- until cX == x
- else
- --print("already there")
- end
- end
- function moveToZ(z)
- if cZ < z then
- turnTo(2)
- repeat
- moveForward()
- until cZ == z
- elseif cZ > z then
- turnTo(0)
- repeat
- moveForward()
- until cZ == z
- else
- --print("already there")
- end
- end
- function moveToY(y)
- if cY < y then
- repeat
- moveUp()
- until cY == y
- elseif cY > y then
- repeat
- moveDown()
- until cY == y
- else
- --print("already there")
- end
- end
- function goTo(x,y,z,dir)
- moveToX(x)
- moveToZ(z)
- moveToY(y)
- turnTo(dir)
- end
- function returnTo(x,y,z,dir)
- moveToY(y)
- moveToX(x)
- moveToZ(z)
- turnTo(dir)
- end
- if tArgs[9]=="return" then
- returnTo(tonumber(tArgs[5]), tonumber(tArgs[6]), tonumber(tArgs[7]),tonumber(tArgs[8]))
- elseif tArgs[9]==nil then
- goTo(tonumber(tArgs[5]), tonumber(tArgs[6]), tonumber(tArgs[7]),tonumber(tArgs[8]))
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement