Advertisement
eytixis

Go to Waypoint (Opencomputers mod)

Oct 1st, 2020 (edited)
1,239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.86 KB | None | 0 0
  1. local component = require("component")
  2. local term = require("term")
  3. local sides = require("sides")
  4. local robot = require("robot")
  5.  
  6. local navigation = component.navigation
  7.  
  8. local waypoint = nil
  9.  
  10. local arguments = {...}
  11.  
  12. local function getWaypoint(name, range)
  13.     local navs = navigation.findWaypoints(range)
  14.     if (navs.n == 0) then
  15.         return nil
  16.     end
  17.     for key,amount in pairs(navs) do
  18.         if (amount.label == name) then
  19.             return amount
  20.         end
  21.     end
  22.     return nil
  23. end
  24.  
  25. local function goHeight(height)
  26.     if (-waypoint.position[2] > height) then
  27.         for i = 1,(-waypoint.position[2]-height) do
  28.             robot.down()
  29.         end
  30.     elseif (-waypoint.position[2] < height) then
  31.         for i = 1,(height+waypoint.position[2]) do
  32.             robot.up()
  33.         end
  34.     end
  35. end
  36.  
  37. local function goHorizontial()
  38.  
  39.     if waypoint.position[1] == 0 then
  40.         return nil
  41.     elseif waypoint.position[1] > 0 then
  42.         while (navigation.getFacing() ~= 5) do
  43.             robot.turnLeft()
  44.         end
  45.         for i = 1,waypoint.position[1] do
  46.             robot.forward()
  47.         end
  48.         return nil
  49.     elseif waypoint.position[1] < 0 then
  50.         while (navigation.getFacing() ~= 4) do
  51.             robot.turnLeft()
  52.         end
  53.         for i = 1,math.abs(waypoint.position[1]) do
  54.             robot.forward()
  55.         end
  56.         return nil
  57.     end
  58. end
  59.  
  60. local function goVertical()
  61.     if waypoint.position[3] == 0 then
  62.         return nil
  63.     elseif waypoint.position[3] > 0 then
  64.         while (navigation.getFacing() ~= 3) do
  65.             robot.turnLeft()
  66.         end
  67.         for i = 1,waypoint.position[3] do
  68.             robot.forward()
  69.         end
  70.         return nil
  71.     elseif waypoint.position[3] < 0 then
  72.         while (navigation.getFacing() ~= 2) do
  73.             robot.turnLeft()
  74.         end
  75.         for i = 1,math.abs(waypoint.position[3]) do
  76.             robot.forward()
  77.         end
  78.         return nil
  79.     end
  80. end
  81.  
  82. if (#arguments == 0) then
  83.     print("Usage: <program> <waypoint>")
  84.     return nil
  85. end
  86.  
  87. waypoint = getWaypoint(arguments[1], 32)
  88. local height = 25
  89. if (waypoint == nil) then
  90.     waypoint = getWaypoint(arguments[1], 64)
  91.     height = 40
  92. end
  93. if (waypoint == nil) then
  94.     waypoint = getWaypoint(arguments[1], 128)
  95.     height = 60
  96. end
  97. if (waypoint == nil) then
  98.     waypoint = getWaypoint(arguments[1], 256)
  99.     height = 80
  100. end
  101. if (waypoint == nil) then
  102.     print("Could not find the waypoint!")
  103.     return nil
  104. end
  105.  
  106. goHeight(height)
  107. waypoint = getWaypoint(arguments[1], 32)
  108. local height = 25
  109. if (waypoint == nil) then
  110.     waypoint = getWaypoint(arguments[1], 64)
  111.     height = 40
  112. end
  113. if (waypoint == nil) then
  114.     waypoint = getWaypoint(arguments[1], 128)
  115.     height = 60
  116. end
  117. if (waypoint == nil) then
  118.     waypoint = getWaypoint(arguments[1], 256)
  119.     height = 80
  120. end
  121. if (waypoint == nil) then
  122.     print("Could not find the waypoint!")
  123.     return nil
  124. end
  125. goHorizontial()
  126. waypoint = getWaypoint(arguments[1], 32)
  127. local height = 25
  128. if (waypoint == nil) then
  129.     waypoint = getWaypoint(arguments[1], 64)
  130.     height = 40
  131. end
  132. if (waypoint == nil) then
  133.     waypoint = getWaypoint(arguments[1], 128)
  134.     height = 60
  135. end
  136. if (waypoint == nil) then
  137.     waypoint = getWaypoint(arguments[1], 256)
  138.     height = 80
  139. end
  140. if (waypoint == nil) then
  141.     print("Could not find the waypoint!")
  142.     return nil
  143. end
  144. goVertical()
  145. waypoint = getWaypoint(arguments[1], 32)
  146. local height = 25
  147. if (waypoint == nil) then
  148.     waypoint = getWaypoint(arguments[1], 64)
  149.     height = 40
  150. end
  151. if (waypoint == nil) then
  152.     waypoint = getWaypoint(arguments[1], 128)
  153.     height = 60
  154. end
  155. if (waypoint == nil) then
  156.     waypoint = getWaypoint(arguments[1], 256)
  157.     height = 80
  158. end
  159. if (waypoint == nil) then
  160.     print("Could not find the waypoint!")
  161.     return nil
  162. end
  163. goHeight(0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement