Advertisement
nagoL2015

Drone

Aug 26th, 2018
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.67 KB | None | 0 0
  1. local xCoord = 110
  2. local yCoord = 67
  3. local zCoord = -26
  4. local targetCoordX = 0
  5. local targetCoordY = 0
  6. local targetCoordZ = 0
  7. local yTravel = 105
  8.  
  9. locations = {home = {108, 69, -26}}
  10.  
  11. local m = component.proxy(component.list('modem')())
  12. local drone = component.proxy(component.list('drone')())
  13. local l = component.proxy(component.list('leash')())
  14.  
  15. function wait()
  16.   while drone.getOffset() > 0.7 or drone.getVelocity() > 0.9 do
  17.     computer.pullSignal(0.2)
  18.   end
  19. end
  20.  
  21. m.open(2412)
  22. local function respond(...)
  23.   local args = table.pack(...)
  24.   pcall(function() m.broadcast(2412, table.unpack(args)) end)
  25. end
  26.  
  27. local function recieve()
  28.   while true do
  29.     local evt, _, _, _, _, cmds = computer.pullSignal()
  30.     if evt == "modem_message" then
  31.       return cmds
  32.     end
  33.   end
  34. end
  35.  
  36. while true do
  37.   local result, reason = pcall(function()
  38.     local result = recieve()
  39.     if not result or result == "" then
  40.       return
  41.     end
  42.     local words = {}
  43.     for word in result:gmatch("([^%s]+)") do
  44.       table.insert(words, word)
  45.     end
  46.     if words[1] == "goto" then
  47.       targetCoordX = words[3]-xCoord
  48.       targetCoordZ = words[5]-zCoord
  49.       drone.move(0, (yTravel-yCoord), 0)
  50.       wait()
  51.       yCoord = yTravel
  52.       drone.move(targetCoordX, 0, targetCoordZ)
  53.       wait()
  54.       targetCoordY = words[4]-yCoord
  55.       drone.move(0, targetCoordY, 0)
  56.       wait()
  57.       xCoord = words[3]
  58.       yCoord = words[4]
  59.       zCoord = words[5]
  60.     elseif words[1] == "leash" then
  61.       l.leash(0)
  62.     else
  63.       local ok,err = pcall(load(result))
  64.       if not ok then
  65.         respond(err)
  66.       end
  67.     end
  68.   end)
  69.   if not result then respond(reason) end
  70. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement