View difference between Paste ID: KMcU0HKB and a3GBewNp
SHOW: | | - or go back to the newest paste.
1
function gotoapi(gx, gy, gz, enddirlet)
2-
    --local tArgs = {...}
2+
--local tArgs = {...}
3-
    face = 0
3+
local face = 0
4-
    local r = 1
4+
local r = 1
5-
    tru = 1
5+
tru = 1
6-
    local tturned = 0
6+
local tturned = 0
7-
    rednet.open("left")
7+
rednet.open("left")
8-
    local cx,cy,cz = gps.locate(2,false)
8+
local cx,cy,cz = gps.locate(2,false)
9-
    if (gx and gy and gz) == nil then
9+
if (gx and gy and gz) == nil then
10-
      print("Incorrect usage of Function.")
10+
  print("Incorrect usage of Function.")
11-
      --print("goto <x> <y> <z> (<Heading>)")
11+
  --print("goto <x> <y> <z> (<Heading>)")
12-
    else
12+
else
13-
    --local gx = tonumber(tArgs[1])
13+
--local gx = tonumber(tArgs[1])
14-
    --local gy = tonumber(tArgs[2])
14+
--local gy = tonumber(tArgs[2])
15-
    --local gz = tonumber(tArgs[3])
15+
--local gz = tonumber(tArgs[3])
16-
    --local enddirlet = tArgs[4]
16+
--local enddirlet = tArgs[4]
17-
    local x
17+
local x
18-
    local y
18+
local y
19-
    local z
19+
local z
20-
    if enddirlet ~= nil then
20+
if enddirlet ~= nil then
21-
        if enddirlet == "n" or enddirlet == "north" then
21+
    if enddirlet == "n" or enddirlet == "north" then
22-
            enddir = 4
22+
        enddir = 4
23-
        end
23+
24-
        if enddirlet == "s" or enddirlet == "south" then
24+
    if enddirlet == "s" or enddirlet == "south" then
25-
            enddir = 2
25+
        enddir = 2
26-
        end
26+
27-
        if enddirlet == "e" or enddirlet == "east" then
27+
    if enddirlet == "e" or enddirlet == "east" then
28-
            enddir = 1
28+
        enddir = 1
29-
        end
29+
30-
        if enddirlet == "w" or enddirlet == "west" then
30+
    if enddirlet == "w" or enddirlet == "west" then
31-
            enddir = 3
31+
        enddir = 3
32-
        end
32+
33
end
34-
    function tturnup()
34+
function tturnup()
35-
        tturned = tturned + 1
35+
    tturned = tturned + 1
36-
        if tturned > 25 then
36+
    if tturned > 10 then
37-
            os.reboot()
37+
        os.reboot()
38-
        end
38+
39
end
40
41-
    function c_face()
41+
function PL()
42-
        while face >= 5 do
42+
  --print("Going to:")
43-
            face = face - 4
43+
  --write(gx) write(" ") write(gy) write(" ") print(gz)
44-
        end
44+
45-
        while face <= 0 do
45+
function c_face()
46-
            face = face + 4
46+
if face >= 5 then
47-
        end
47+
  face = 1
48
elseif face <= 0 then
49
  face = 4
50
end
51
end
52
function get_Face()
53-
function gps_face_math(cur_x,cur_z)
53+
while turtle.forward() == false do
54-
  mnx,mny,mnz = gps.locate(3,false)
54+
55-
  if mnx > cur_x then
55+
56-
    face = 1
56+
57
  end
58-
  if mnx < cur_x then
58+
59-
    face = 3
59+
nx,ny,nz = gps.locate(3,false)
60
if nx > cx then
61-
  if mnz > cur_z then
61+
  face = 1
62-
    face = 2
62+
63
if nx < cx then
64-
  if mnz < cur_z then
64+
  face = 3
65-
    face = 4
65+
66
if nz > cz then
67
  face = 2
68-
function forward_get_face()
68+
69-
  tturned = 0
69+
if nz < cz then
70-
  cux,cuy,cuz = gps.locate(3,false)
70+
  face = 4
71-
  while turtle.forward() == false do
71+
72
end
73
function calc()
74
x = nx - gx
75
y = ny - gy
76
z = nz - gz
77-
  gps_face_math(cux,cuz)
77+
78-
  return true
78+
function setDir(dir)
79
while dir ~= face do
80
  c_face()
81
    if face >= dir then
82
        turtle.turnLeft()
83-
    function get_Face()
83+
        face = face - 1
84-
    while turtle.forward() == false do
84+
        tturnup()
85-
        tturned = 0
85+
86-
       if turtle.up() == false then
86+
    if face < dir then
87-
            --turtle.digUp()
87+
        turtle.turnRight()
88-
       end
88+
        face = face + 1
89-
      end
89+
        tturnup()
90-
    nx,ny,nz = gps.locate(3,false)
90+
91-
    gps_face_math(cx,cz)
91+
  c_face()
92
  end
93-
    function calc()
93+
94-
    x = nx - gx
94+
function f()
95-
    y = ny - gy
95+
while not turtle.forward() do
96-
    z = nz - gz
96+
97
   if not turtle.up()  then
98-
    function setDir(dir)
98+
99-
        noredoturndir = 0
99+
100-
      c_face()
100+
   y = y + 1
101-
      if dir == 4 then
101+
102-
        if face == 1 then
102+
103-
            gototurnleft = 1
103+
function go()
104-
            --print("E-to-N")
104+
105-
            noredoturndir = 1
105+
if x < 0 then
106-
        end
106+
  setDir(1)
107-
      end
107+
  while x ~= 0 do
108-
      if dir == 1 then
108+
   f()
109-
        if face == 4 then
109+
   x = x + 1
110-
            gototurnleft = 0
110+
111-
            --print("N-to-E")
111+
112-
            noredoturndir = 1
112+
if x > 0 then
113-
        end
113+
  setDir(3)
114-
      end
114+
  while x ~= 0 do
115-
    
115+
   f()
116-
      if noredoturndir == 0 then
116+
   x = x - 1
117-
         if face >= dir then
117+
118-
            gototurnleft = 1
118+
119-
         end
119+
if z < 0 then
120-
         if face < dir then
120+
  setDir(2)
121-
            gototurnleft = 0
121+
  while z ~= 0 do
122-
        end
122+
   f()
123-
      end
123+
   z = z + 1
124-
      
124+
125-
      if dir == 4 then
125+
126-
        if face == 1 then
126+
if z > 0 then
127-
            gototurnleft = 1
127+
  setDir(4)
128-
            --print("E-to-N")
128+
  while z ~= 0 do
129-
            noredoturndir = 1
129+
   f()
130-
        end
130+
   z = z - 1
131-
      end
131+
132-
      if dir == 1 then
132+
133-
        if face == 4 then
133+
while y < 0 do
134-
            gototurnleft = 0
134+
135-
            --print("N-to-E")
135+
  if turtle.up() ~= true then
136-
            noredoturndir = 1
136+
   --turtle.digUp()
137-
        end
137+
138-
      end
138+
  y = y + 1
139-
      while dir ~= face do
139+
140-
        c_face()
140+
while y > 0 do
141-
        if gototurnleft == 1 then
141+
142-
            turtle.turnLeft()
142+
  if turtle.down() ~= true then
143-
            face = face - 1
143+
   --turtle.digDown()
144-
            tturnup()
144+
145-
        end
145+
  y = y - 1
146-
        if gototurnleft == 0 then
146+
147-
            turtle.turnRight()
147+
148-
            face = face + 1
148+
149-
            tturnup()
149+
150-
        end
150+
151-
      c_face()
151+
tonumber(gx)
152-
      end
152+
tonumber(gy)
153-
      noredoturndir = 0
153+
tonumber(gz)
154
PL()
155-
    function f()
155+
get_Face()
156-
        while not forward_get_face() do
156+
calc()
157-
        tturned = 0
157+
go()
158-
        if not turtle.up()  then
158+
if enddir ~= nil then
159-
            --turtle.digUp()
159+
    setDir(enddir)
160-
        end
160+
161-
        y = y + 1
161+
162-
        end
162+
163
end