Advertisement
Agent_Silence

QuadcopAPI

Jan 2nd, 2015
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.06 KB | None | 0 0
  1. local function side()
  2.   for i,v in pairs(peripheral.getNames()) do
  3.     if peripheral.getType(v) == "quadbase" then
  4.       return v
  5.     end
  6.   end
  7. end
  8.  
  9. function gotoCoords(x,y,z,fromPosx,fromPosy,fromPosz)
  10.   if gps.locate() ~= nil and side() == "top" then
  11.     local a,b,c = gps.locate()
  12.     fromPosx = a
  13.     fromPosy = b + 2
  14.     fromPosz = c
  15.   end
  16.   local program = {}
  17.   table.insert(program,"up "..tostring(150 - fromPosy))
  18.   table.insert(program,"east "..tostring(fromPosx - x))
  19.   table.insert(program,"north "..tostring(fromPosz - z))
  20.   table.insert(program,"down "..tostring(150 - y))
  21.   return program
  22. end
  23.  
  24. function qReturn(tCode,x,y,z,fromPosx,fromPosy,fromPosz)
  25.   if gps.locate() ~= nil and side() == "top" then
  26.     local a,b,c = gps.locate()
  27.     x = a
  28.     y = b + 2
  29.     z = c
  30.   end
  31.   local program = tCode
  32.   table.insert(program,"up "..tostring(150 - fromPosy))
  33.   table.insert(program,"east "..tostring(fromPosx - x))
  34.   table.insert(program,"north "..tostring(fromPosz - z))
  35.   table.insert(program,"down "..tostring(150 - y))
  36.   return program
  37. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement