Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- args = {...}
- function split(_string)
- local _arr = {}
- for i in string.gmatch(_string, '([^,]+)') do
- table.insert(_arr,i)
- end
- return _arr
- end
- position = assert(loadfile("getPos"))()
- if position == nil then
- x = 1
- y = 1
- z = 1
- f = 1
- else
- position = split(position)
- x = tonumber(position[1])
- y = tonumber(position[2])
- z = tonumber(position[3])
- f = tonumber(position[4])
- end
- m_table = {
- ["fd"] = function()
- if(turtle.forward()) then
- if (f == 1) then
- z = z+1
- elseif (f == 2) then
- x = x+1
- elseif (f == 3) then
- z = z-1
- elseif (f == 4) then
- x = x-1
- end
- return true
- else return false end
- end,
- ["bk"] = function()
- if(turtle.back()) then
- if (f == 1) then
- z = z-1
- elseif (f == 2) then
- x = x-1
- elseif (f == 3) then
- z = z+1
- elseif (f == 4) then
- x = x+1
- end
- return true
- else return false end
- end,
- ["rt"] = function()
- if(turtle.turnRight()) then
- if (f < 4) then
- f = f+1
- else
- f = 1
- end
- return true
- else return false end
- end,
- ["lt"] = function()
- if(turtle.turnLeft()) then
- if (f > 1) then
- f = f-1
- else
- f = 4
- end
- return true
- else return false end
- end,
- ["up"] = function()
- if(turtle.up()) then
- y = y + 1
- return true
- else return false end
- end,
- ["dn"] = function()
- if(turtle.down()) then
- y = y - 1
- return true
- else
- return false
- end
- end
- }
- function move(direction)
- local _move = m_table[direction]
- if (_move) then
- test = _move()
- return test
- end
- end
- function moveCoords(_x,_y,_z,_f)
- moveY(_x,_y,_z,_f)
- moveX(_x,_y,_z,_f)
- moveZ(_x,_y,_z,_f)
- -- Adjust facing
- if (f ~= _f) then
- repeat
- move("lt")
- until(f == _f)
- end
- if (x ~= _x or y ~= _y or z ~= _z) then
- moveCoords(_x,_y,_z,_f)
- end
- end
- function moveY(_x,_y,_z,_f)
- -- Height
- while y < _y and move("up") do end
- while y > _y and move("dn") do end
- if (y ~= _y) then
- if (math.abs(x-_x)>math.abs(z-_z)) then
- moveX(x+1,_y,_z,_f)
- else
- moveZ(_x,_y,z+1,_f)
- end
- moveY(_x,_y,_z,_f)
- end
- end
- function moveX(_x,_y,_z,_f)
- --Adjust facing for x axis
- if (f ~= 2 and x ~= _x) then
- repeat
- move("rt")
- until(f == 2)
- end
- -- X axis
- while x < _x and move("fd") do end
- while x > _x and move("bk") do end
- if (x ~= _x) then
- moveY(_x,y+1,_z,_f)
- moveX(_x,_y,_z,_f)
- end
- end
- function moveZ(_x,_y,_z,_f)
- -- Adjust facing for z axis
- if (f ~= 1 and z ~= _z) then
- repeat
- move("lt")
- until(f == 1)
- end
- -- Z axis
- while z < _z and move("fd") do end
- while z > _z and move("bk") do end
- if (z ~= _z) then
- moveY(_x,y+1,_z,_f)
- moveZ(_x,_y,_z,_f)
- end
- end
- if (args[2] == nil) then
- move(args[1])
- elseif (args[1] ~= nil) then
- moveCoords(tonumber(args[1]),tonumber(args[2]),tonumber(args[3]),tonumber(args[4]))
- end
- file = fs.open("/.pos", "w")
- file.writeLine(x..","..y..","..z..","..f)
- file.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement