﻿

# WaifuSepeti

Nov 25th, 2020 (edited)
661
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. -- Wireless Miner Turtle GPS goto program
2.
3. local tArgs = {...}
4. local x = tonumber(tArgs[1])
5. local y = tonumber(tArgs[3])
6. local z = tonumber(tArgs[2])
7. local dirs = string
8. local dir, disx, disy, disz = 0, 0, 0, 0
9. local height, forward = 0, 0
10. local ox, oy, oz = 0, 0, 0
11.
12. if #tArgs < 3 or #tArgs > 3 then
13.  print( "Usage: <Program> <x> <z> <y>" )
14.  return
15. end
16.
17. function fuellevel()
18.  fuel = turtle.getFuelLevel()
19.  if fuel == "unlimited" then
20.   print("Fuel Level: Unlimited")
21.   return true
22.  end
23.  if fuel > 79 then
24.   print("Fuel Level: "..tostring(fuel))
25.   return true
26.  else
27.   print("Fuel Level: Low")
29.   return false
30.  end
31. end
32.
33. function calc()
34. -- Getting current location
35. -- Original x (ox)...
36.  ox, oy, oz = gps.locate(3)
37. -- Solving for distance by subtracting new location from current location
38. -- Distance x (disx)...
39.  disx = ox - x
40.  disy = oy - y
41.  disz = oz - z
42.  getdir()
43. end
44.
45. function getdir()
46. -- Solving for what direction the turtle is faceing
47.  if turtle.detect() == true then
48.   if not turtle.back() then
49.    print( "Please remove block in front or back of turtle" )
50.    sleep(5)
51.    os.reboot()
52.   else
53. -- When forward = 1, means the turtle went backwards
54.    forward = 1
55. -- Getting new GPS location
56. -- Directional new x (dnx) ...
57.    dnx, dny, dnz = gps.locate(3)
58.    sleep(0.2)
59.    turtle.forward()
60.    sleep(0.2)
61.   end
62.  else
63. -- When forward = 0, means the turtle went forwards
64.   forward = 0
65.   turtle.forward()
66. -- Getting new GPS location
67. -- Directional new x (dnx) ...
68.   dnx, dny, dnz = gps.locate(3)
69.   sleep(0.2)
70.   turtle.back()
71.   sleep(0.2)
72.  end
73. -- Solving direction by subtracting directional x/y from original x/y
74. -- Directional curent x (dcx)...
75.  dcx = ox - dnx
76.  dcz = oz - dnz
77. -- If the diferances in dcx or dcz are negative/Positive and if the turtle went backwards/forwards determins the direction
78. -- Direction (dir) and Direction String (dirs)
79.  if dcx > 0 then
80.   if forward == 0 then
81.    dirs = "West"
82.    dir = 1
83.   else
84.    dirs = "East"
85.    dir = 3
86.   end
87.  end
88.  if dcx < 0 then
89.   if forward == 0 then
90.    dirs = "East"
91.    dir = 3
92.   else
93.    dirs = "West"
94.    dir = 1
95.   end
96.  end
97.  if dcz > 0 then
98.   if forward == 0 then
99.    dirs = "North"
100.    dir = 2
101.   else
102.    dirs = "South"
103.    dir = 0
104.   end
105.  end
106.  if dcz < 0 then
107.   if forward == 0 then
108.    dirs = "South"
109.    dir = 0
110.   else
111.    dirs = "North"
112.    dir = 2
113.   end
114.  end
115. end
116.
117. function tryfwd()
118.  while turtle.detect() == true do
119.   tryup()
120.   turtle.up()
121.   height = height + 1
122.  end
123. end
124.
125. function dobck()
126.  while not turtle.back() do
127.   tryup()
128.   turtle.up()
129.   height = height + 1
130.  end
131. end
132.
133. function tryup()
134.  if turtle.detectUp() == true then
135.   turtle.digUp()
136.  end
137. end
138.
139. function trydwn()
140.  if turtle.detectDown() == true then
141.   turtle.digDown()
142.  end
143. end
144.
145. function updown()
146. -- If distance y is a neagtive number then make it positive
147. -- Modified Distance Y (mdisy)...
148. disy = 115 - disy
149.
150.  if disy < 0 then
151.   mdisy = disy * -1
152.   for a = 1, mdisy do
153.    tryup()
154.    turtle.up()
155.   end
156.  end
157.  if disy > 0 then
158.   for b = 1, disy do
159.    trydwn()
160.    turtle.down()
161.   end
162.  end
163. end
164.
165. function flightHeight()
166.     newDist = 115 - oy
167.     for i = 1, newDist do
168.         tryup()
169.         turtle.up()
170.     end
171. end
172.
173. -- This block of code determins how far to go and what direction to go, baised off of what direction the turtle is facing,
174. -- and if disx/disy/disz is positive or negative
175. function move()
176. -- If facing West (1)
177.  if dir == 1 then
178.   flightHeight()
179.   if disx < 0 then
180.    mdisx = disx * -1
181.    for c = 1, mdisx do
182.     dobck()
183.    end
184.   end
185.   if disx > 0 then
186.    for d = 1, disx do
187.     tryfwd()
188.     turtle.forward()
189.    end
190.   end
191.   if disz < 0 then
192.    mdisz = disz * -1
193.    turtle.turnLeft()
194.    for e = 1, mdisz do
195.     tryfwd()
196.     turtle.forward()
197.    end
198.   end
199.   if disz > 0 then
200.    turtle.turnRight()
201.    for f = 1, disz do
202.     tryfwd()
203.     turtle.forward()
204.    end
205.   end
206.   updown()
207.  end
208. -- If facing North (2)
209.  if dir == 2 then
210.   flightHeight()
211.   if disz < 0 then
212.    mdisz = disz * -1
213.    for i = 1, mdisz do
214.     dobck()
215.    end
216.   end
217.   if disz > 0 then
218.    for j = 1, disz do
219.     tryfwd()
220.     turtle.forward()
221.    end
222.   end
223.   if disx < 0 then
224.    mdisx = disx * -1
225.    turtle.turnRight()
226.    for k = 1, mdisx do
227.     tryfwd()
228.     turtle.forward()
229.    end
230.   end
231.   if disx > 0 then
232.    turtle.turnLeft()
233.    for l = 1, disx do
234.     tryfwd()
235.     turtle.forward()
236.    end
237.   end
238.   updown()
239.  end
240. -- If facing East (3)
241.  if dir == 3 then
242.   flightHeight()
243.   if disx < 0 then
244.    mdisx = disx * -1
245.    for o = 1, mdisx do
246.     tryfwd()
247.     turtle.forward()
248.    end
249.   end
250.   if disx > 0 then
251.    for p = 1, disx do
252.     dobck()
253.    end
254.   end
255.   if disz < 0 then
256.    mdisz = disz * -1
257.    turtle.turnRight()
258.    for q = 1, mdisz do
259.     tryfwd()
260.     turtle.forward()
261.    end
262.   end
263.   if disz > 0 then
264.    turtle.turnLeft()
265.    for r = 1, disz do
266.     tryfwd()
267.     turtle.forward()
268.    end
269.   end
270.   updown()
271.  end
272.  -- If facing South (0)
273.  if dir == 0 then
274.   flightHeight()
275.   if disz < 0 then
276.    mdisz = disz * -1
277.    for u = 1, mdisz do
278.     tryfwd()
279.     turtle.forward()
280.    end
281.   end
282.   if disz > 0 then
283.    for v = 1, disz do
284.     dobck()
285.    end
286.   end
287.   if disx < 0 then
288.    mdisx = disx * -1
289.    turtle.turnLeft()
290.    for w = 1, mdisx do
291.     tryfwd()
292.     turtle.forward()
293.    end
294.   end
295.   if disx > 0 then
296.    turtle.turnRight()
297.    for aa = 1, disx do
298.     tryfwd()
299.     turtle.forward()
300.    end
301.   end
302.   updown()
303.  end
304. -- If the turtle had to go up because of an obstacle this will make the turtle go down to it's destination
305.  for ab = 1, height do
306.   trydwn()
307.   turtle.down()
308.  end
309. end
310.
311. rednet.open("left")
312. term.clear()
313. term.setCursorPos(1, 1)
314. if fuellevel() == true then
315.  calc()
316.  sleep(0.2)
317.  print("Facing: "..dirs)
318.  print("Distance: X = "..disx..", Z = "..disz..", Y = "..disy)
319.  print("")
320.  sleep(0.2)
321.  move()
322. -- Checking if the program was successful
323. -- Destination x (dx)...
324.  dx, dy, dz = gps.locate(3)
325.  if dx == x and dy == y and dz == z then
326.   print("Have arrived at "..x..", "..z..", "..y )
327.  else
328.   print("Something went wrong, try again")
329.  end
330. end
RAW Paste Data