maxheyer

Untitled

Jan 3rd, 2018
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.18 KB | None | 0 0
  1. local function proxyFor(name, required)
  2.   local address = component and component.list(name)()
  3.   if not address and required then
  4.     --error("missing component '" .. name .. "'")
  5.   end
  6.   return address and component.proxy(address) or nil
  7. end
  8.  
  9. local drone = proxyFor("drone", true)
  10. local nav = proxyFor("navigation", true)
  11. local range = 15
  12.  
  13. local charger = nil
  14. local farm = nil
  15. local storage = nil
  16.  
  17. local function updateWaypoints()
  18.   for _, w in ipairs(nav.findWaypoints(range)) do
  19.     if w.label == "charger" then
  20.       charger = w
  21.     elseif w.label == "farm" then
  22.       farm = w
  23.     elseif w.label == "storage" then
  24.       storage = w
  25.     end
  26.   end
  27.  
  28.   if charger == nil or farm == nil or storage == nil then
  29.     error("waypoints missing")
  30.     os.exit()
  31.   end
  32. end
  33.  
  34. -- Keep track of our own position, relative to our starting position.
  35. local px, py, pz = 0, 0, 0
  36.  
  37. local function moveTo(x, y, z)
  38.   if type(x) == "table" then
  39.     x, y, z = x[1], x[2], x[3]
  40.   end
  41.   local rx, ry, rz = x - px, y - py, z - pz
  42.   drone.move(rx, ry, rz)
  43.   px, py, pz = x, y, z
  44. end
  45.  
  46. while true do
  47.   updateWaypoints()
  48. --moveTo(charger.position.x, charger.position.y, charger.position.z)
  49. end
Add Comment
Please, Sign In to add comment