View difference between Paste ID: a3GBewNp and Rj9UiYUJ
SHOW: | | - or go back to the newest paste.
1-
local tArgs = {...}
1+
function gotoapi(gx, gy, gz, enddirlet)
2-
local face = 0
2+
    --local tArgs = {...}
3-
local r = 1
3+
    face = 0
4-
local tturned = 0
4+
    local r = 1
5-
rednet.open("left")
5+
    tru = 1
6-
local cx,cy,cz = gps.locate(2,false)
6+
    local tturned = 0
7-
if #tArgs ~= 3 and #tArgs ~= 4 then
7+
    rednet.open("left")
8-
  print("Incorrect usage of Function.")
8+
    local cx,cy,cz = gps.locate(2,false)
9-
  --print("goto <x> <y> <z> (<Heading>)")
9+
    if (gx and gy and gz) == nil then
10-
else
10+
      print("Incorrect usage of Function.")
11-
local gx = tonumber(tArgs[1])
11+
      --print("goto <x> <y> <z> (<Heading>)")
12-
local gy = tonumber(tArgs[2])
12+
    else
13-
local gz = tonumber(tArgs[3])
13+
    --local gx = tonumber(tArgs[1])
14-
local enddirlet = tArgs[4]
14+
    --local gy = tonumber(tArgs[2])
15-
local x
15+
    --local gz = tonumber(tArgs[3])
16-
local y
16+
    --local enddirlet = tArgs[4]
17-
local z
17+
    local x
18
    local y
19-
if enddirlet == "n" or enddirlet == "north" then
19+
    local z
20-
    enddir = 4
20+
    if enddirlet ~= nil then
21
        if enddirlet == "n" or enddirlet == "north" then
22-
if enddirlet == "s" or enddirlet == "south" then
22+
            enddir = 4
23-
    enddir = 2
23+
        end
24
        if enddirlet == "s" or enddirlet == "south" then
25-
if enddirlet == "e" or enddirlet == "east" then
25+
            enddir = 2
26-
    enddir = 1
26+
        end
27
        if enddirlet == "e" or enddirlet == "east" then
28-
if enddirlet == "w" or enddirlet == "west" then
28+
            enddir = 1
29-
    enddir = 3
29+
        end
30
        if enddirlet == "w" or enddirlet == "west" then
31
            enddir = 3
32-
function tturnup()
32+
        end
33-
tturned = tturned + 1
33+
34-
if tturned > 10 then
34+
    function tturnup()
35-
os.reboot()
35+
        tturned = tturned + 1
36
        if tturned > 25 then
37
            os.reboot()
38
        end
39-
function PL()
39+
40-
  --print("Going to:")
40+
41-
  --write(gx) write(" ") write(gy) write(" ") print(gz)
41+
    function c_face()
42
        while face >= 5 do
43-
function c_face()
43+
            face = face - 4
44-
if face >= 5 then
44+
        end
45-
  face = 1
45+
        while face <= 0 do
46-
elseif face <= 0 then
46+
            face = face + 4
47-
  face = 4
47+
        end
48
    end
49
50-
function get_Face()
50+
51-
while turtle.forward() == false do
51+
52
53
function gps_face_math(cur_x,cur_z)
54
  mnx,mny,mnz = gps.locate(3,false)
55
  if mnx > cur_x then
56
    face = 1
57-
nx,ny,nz = gps.locate(3,false)
57+
58-
if nx > cx then
58+
  if mnx < cur_x then
59-
  face = 1
59+
    face = 3
60
  end
61-
if nx < cx then
61+
  if mnz > cur_z then
62-
  face = 3
62+
    face = 2
63
  end
64-
if nz > cz then
64+
  if mnz < cur_z then
65-
  face = 2
65+
    face = 4
66
  end
67-
if nz < cz then
67+
68-
  face = 4
68+
function forward_get_face()
69
  tturned = 0
70
  cux,cuy,cuz = gps.locate(3,false)
71-
function calc()
71+
  while turtle.forward() == false do
72-
x = nx - gx
72+
73-
y = ny - gy
73+
74-
z = nz - gz
74+
75
   end
76-
function setDir(dir)
76+
77-
while dir ~= face do
77+
  gps_face_math(cux,cuz)
78-
  c_face()
78+
  return true
79-
    if face >= dir then
79+
80-
        turtle.turnLeft()
80+
81-
        face = face - 1
81+
82-
        tturnup()
82+
83
    function get_Face()
84-
    if face < dir then
84+
    while turtle.forward() == false do
85-
        turtle.turnRight()
85+
        tturned = 0
86-
        face = face + 1
86+
       if turtle.up() == false then
87-
        tturnup()
87+
            --turtle.digUp()
88
       end
89-
  c_face()
89+
      end
90
    nx,ny,nz = gps.locate(3,false)
91
    gps_face_math(cx,cz)
92-
function f()
92+
93-
while not turtle.forward() do
93+
    function calc()
94
    x = nx - gx
95-
   if not turtle.up()  then
95+
    y = ny - gy
96
    z = nz - gz
97
    end
98-
   y = y + 1
98+
    function setDir(dir)
99
        noredoturndir = 0
100
      c_face()
101-
function go()
101+
      if dir == 4 then
102
        if face == 1 then
103-
if x < 0 then
103+
            gototurnleft = 1
104-
  setDir(1)
104+
            --print("E-to-N")
105-
  while x ~= 0 do
105+
            noredoturndir = 1
106-
   f()
106+
        end
107-
   x = x + 1
107+
      end
108
      if dir == 1 then
109
        if face == 4 then
110-
if x > 0 then
110+
            gototurnleft = 0
111-
  setDir(3)
111+
            --print("N-to-E")
112-
  while x ~= 0 do
112+
            noredoturndir = 1
113-
   f()
113+
        end
114-
   x = x - 1
114+
      end
115
    
116
      if noredoturndir == 0 then
117-
if z < 0 then
117+
         if face >= dir then
118-
  setDir(2)
118+
            gototurnleft = 1
119-
  while z ~= 0 do
119+
         end
120-
   f()
120+
         if face < dir then
121-
   z = z + 1
121+
            gototurnleft = 0
122
        end
123
      end
124-
if z > 0 then
124+
      
125-
  setDir(4)
125+
      if dir == 4 then
126-
  while z ~= 0 do
126+
        if face == 1 then
127-
   f()
127+
            gototurnleft = 1
128-
   z = z - 1
128+
            --print("E-to-N")
129
            noredoturndir = 1
130
        end
131-
while y < 0 do
131+
      end
132
      if dir == 1 then
133-
  if turtle.up() ~= true then
133+
        if face == 4 then
134-
   --turtle.digUp()
134+
            gototurnleft = 0
135
            --print("N-to-E")
136-
  y = y + 1
136+
            noredoturndir = 1
137
        end
138-
while y > 0 do
138+
      end
139
      while dir ~= face do
140-
  if turtle.down() ~= true then
140+
        c_face()
141-
   --turtle.digDown()
141+
        if gototurnleft == 1 then
142
            turtle.turnLeft()
143-
  y = y - 1
143+
            face = face - 1
144
            tturnup()
145
        end
146
        if gototurnleft == 0 then
147
            turtle.turnRight()
148
            face = face + 1
149-
tonumber(gx)
149+
            tturnup()
150-
tonumber(gy)
150+
        end
151-
tonumber(gz)
151+
      c_face()
152-
PL()
152+
      end
153-
get_Face()
153+
      noredoturndir = 0
154-
calc()
154+
155-
go()
155+
    function f()
156-
if #tArgs == 4 then
156+
        while not forward_get_face() do
157-
    setDir(enddir)
157+
        tturned = 0
158
        if not turtle.up()  then
159
            --turtle.digUp()
160-
160+
        end
161
        y = y + 1
162
        end
163
    end
164
    function go()
165
        tturned = 0
166
    if x < 0 then
167
      setDir(1)
168
      while x ~= 0 do
169
       f()
170
       x = x + 1
171
      end
172
    end
173
    if x > 0 then
174
      setDir(3)
175
      while x ~= 0 do
176
       f()
177
       x = x - 1
178
      end
179
    end
180
    if z < 0 then
181
      setDir(2)
182
      while z ~= 0 do
183
       f()
184
       z = z + 1
185
      end
186
    end
187
    if z > 0 then
188
      setDir(4)
189
      while z ~= 0 do
190
       f()
191
       z = z - 1
192
      end
193
    end
194
    while y < 0 do
195
        tturned = 0
196
      if turtle.up() ~= true then
197
       --turtle.digUp()
198
      end
199
      y = y + 1
200
    end
201
    while y > 0 do
202
        tturned = 0
203
      if turtle.down() ~= true then
204
       --turtle.digDown()
205
      end
206
      y = y - 1
207
    end
208
    end
209
    
210
    
211
    
212
    tonumber(gx)
213
    tonumber(gy)
214
    tonumber(gz)
215
    get_Face()
216
    calc()
217
    go()
218
    if enddir ~= nil then
219
        setDir(enddir)
220
    end
221
    
222
    end
223
    end
224
    
225
    
226
    
227
    function goto(Workinggototable)   
228
      gtloop = 0
229
      gtloopsleep = 0.01
230
      gtloopsleep2 = gtloopsleep ^ 2
231
      gototable = {}                    
232
      goit = 1
233
      while true do
234
        while goit < 5 do
235
          if Workinggototable[goit] ~= nil then
236
              table.insert(gototable, Workinggototable[goit])
237
          elseif Workinggototable[goit] == nil then
238
              table.insert(gototable, Workinggototable[goit])
239
              break
240
          end
241
          goit = goit + 1 
242
        end 
243
        gotoapi(gototable[1], gototable[2], gototable[3], gototable[4]) 
244
        local ecx,ecy,ecz = gps.locate(5,false)
245
        if ecx == tonumber(gototable[1]) then
246
          if ecy == tonumber(gototable[2]) then
247
            if ecz == tonumber(gototable[3]) then
248
                if enddir ~= nil then
249
                    if face == enddir then
250
                        break
251
                    end
252
                else
253
                    break
254
                end
255
            end
256
          end
257
        end
258
        if gtloop < 100 then
259
          gtloop = gtloop + 1
260
        end
261
        if gtloop > 5 then     
262
          if gtloopsleep > 2.5 then
263
            gtloopsleep = 2.5
264
          end
265
          if gtloopsleep2 > 2.5 then
266
            gtloopsleep2 = 2.5
267
          end
268
          sleep(gtloopsleep2)
269
          gtloopsleep = gtloopsleep * 1.1
270
          gtloopsleep2 = gtloopsleep ^ 2
271
        end
272
      end
273
    end