remie92

Actual Flyer Program

Jul 17th, 2025 (edited)
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.82 KB | None | 0 0
  1. --Modems:
  2. --91 To Server
  3. --92 To Client
  4.  
  5. sleep(1)
  6.  
  7. for i=1,16 do
  8. turtle.select(i)
  9. turtle.refuel()
  10. end
  11.  
  12.  
  13. print("Starting program")
  14. print("Fuel level:",turtle.getFuelLevel())
  15.  
  16.  
  17.  
  18.  
  19.  
  20. rotation=0
  21.  
  22. firstX,firstY,firstZ=gps.locate()
  23.  
  24. print("Starting coordinates:", firstX, firstY, firstZ)
  25.  
  26. while turtle.detect() do
  27. turtle.turnLeft()
  28. end
  29.  
  30. turtle.forward()
  31. x,y,z=gps.locate()
  32.  
  33. if x<firstX then
  34. rotation=2
  35. end
  36. if x>firstX then
  37. rotation=0
  38. end
  39. if z<firstZ then
  40. rotation=3
  41. end
  42. if z>firstZ then
  43. rotation=1
  44. end
  45.  
  46. print("Current coordinates:", x, y, z, "Rotation:", rotation)
  47.  
  48. modem=peripheral.find("modem")
  49. modem.open(92)
  50.  
  51. modem.transmit(91,92,os.getComputerID())
  52.  
  53. function splitString(str, sep)
  54.  
  55.  
  56. if type(str) ~= "string" then
  57. return {}
  58. end
  59.  
  60. if sep == nil then
  61. sep = " "
  62. end
  63.  
  64. local t = {}
  65. local start = 1
  66.  
  67. while true do
  68. local sepStart, sepEnd = string.find(str, sep, start, true)
  69. if not sepStart then
  70. table.insert(t, string.sub(str, start))
  71. break
  72. end
  73. table.insert(t, string.sub(str, start, sepStart - 1))
  74. start = sepEnd + 1
  75. end
  76.  
  77. return t
  78. end
  79.  
  80.  
  81.  
  82. function turnLeft()
  83. turtle.turnLeft()
  84. rotation=rotation-1
  85. if rotation<0 then
  86. rotation=3
  87. end
  88. end
  89.  
  90. function turnRight()
  91. turtle.turnRight()
  92. rotation=rotation+1
  93. if rotation>3 then
  94. rotation=0
  95. end
  96. end
  97.  
  98. function gotoRotation(rot)
  99. while rotation~=rot do
  100. turnRight()
  101. end
  102. end
  103.  
  104. function goForward()
  105. if turtle.forward()==false then
  106. gotoRotation(math.random(0,3))
  107. turtle.up()
  108. turtle.forward()
  109. turtle.up()
  110. turtle.forward()
  111. end
  112. end
  113.  
  114.  
  115. function goUp()
  116. if turtle.up()==false then
  117. gotoRotation(math.random(0,3))
  118. goForward()
  119. goForward()
  120. turtle.up()
  121. end
  122. end
  123. function goDown()
  124. if turtle.down()==false then
  125. gotoRotation(math.random(0,3))
  126. turtle.forward()
  127. turtle.forward()
  128. turtle.down()
  129. end
  130. end
  131.  
  132. function forceForward()
  133. while turtle.forward()==false do
  134. sleep(0.01)
  135. end
  136. end
  137.  
  138. function forceUp()
  139. while turtle.up()==false do
  140. sleep(0.01)
  141. end
  142. end
  143. function forceDown()
  144. while turtle.down()==false do
  145. sleep(0.01)
  146. end
  147. end
  148.  
  149. function goToLoc(goX,goY,goZ,goDir,force)
  150. if force==0 then
  151. x, y, z = gps.locate()
  152. while x ~= goX or y ~= goY or z ~= goZ do
  153.  
  154. if x < goX then
  155. gotoRotation(0)
  156. goForward()
  157. elseif x > goX then
  158. gotoRotation(2)
  159. goForward()
  160. elseif z < goZ then
  161. gotoRotation(1)
  162. goForward()
  163. elseif z > goZ then
  164. gotoRotation(3)
  165. goForward()
  166. elseif y < goY then
  167. goUp()
  168. elseif y > goY then
  169. goDown()
  170. end
  171. x, y, z = gps.locate()
  172. end
  173. if goDir then
  174. gotoRotation(goDir)
  175. end
  176. end
  177.  
  178. if force==1 then
  179. x, y, z = gps.locate()
  180. while x ~= goX or y ~= goY or z ~= goZ do
  181. if x < goX then
  182. gotoRotation(0)
  183. forceForward()
  184. elseif x > goX then
  185. gotoRotation(2)
  186. forceForward()
  187. elseif z < goZ then
  188. gotoRotation(1)
  189. forceForward()
  190. elseif z > goZ then
  191. gotoRotation(3)
  192. forceForward()
  193. elseif y < goY then
  194. forceUp()
  195. elseif y > goY then
  196. forceDown()
  197. end
  198. x, y, z = gps.locate()
  199. end
  200. if goDir then
  201. gotoRotation(goDir)
  202. end
  203. end
  204.  
  205. end
  206.  
  207.  
  208. while true do
  209. local event, side, channel, replyChannel, message, distance = os.pullEvent("modem_message")
  210. print(("Message received on side %s on channel %d (reply to %d) from %f blocks away with message %s"):format(
  211. side, channel, replyChannel, distance, tostring(message)
  212. ))
  213.  
  214. if message=="reboot" then
  215. print("Rebooting...")
  216. os.reboot()
  217. end
  218.  
  219. splitMessage=splitString(message, " ")
  220. if splitMessage[1]=="forceGo" then
  221. newx=tonumber(splitMessage[2])
  222. newy=tonumber(splitMessage[3])
  223. newz=tonumber(splitMessage[4])
  224. id=tonumber(splitMessage[5])
  225. force=tonumber(splitMessage[6])
  226. if os.getComputerID()==id then
  227. print("Forcing go to coordinates:", newx, newy, newz)
  228. x,y,z=gps.locate()
  229. yDiff=math.random(5,15)
  230. --goToLoc(x,y+yDiff,z,0)
  231. --goToLoc(newx,newy+yDiff,newz,0)
  232. goToLoc(newx,newy,newz,0,force)
  233. end
  234.  
  235. end
  236. end
  237.  
  238.  
Advertisement
Add Comment
Please, Sign In to add comment