blunty666

starNav_goto

Jul 1st, 2014
442
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local function printUsage()
  2.     print("Usage:")
  3.     print(fs.getName(shell.getRunningProgram()).." <map_name> <x_pos> <y_pos> <z_pos> <(optional)max_distance>")
  4.     print("<map_name> The name of the remoteMap to connect to and use.")
  5.     print("<x_pos> <y_pos> <z_pos> The GPS coordinates you want to go to.")
  6.     print("<(optional)max_distance> The farthest distance allowed to travel from start position.")
  7. end
  8.  
  9. if not starNav then
  10.     if not os.loadAPI("starNav") then
  11.         error("could not load starNav API")
  12.     end
  13. end
  14.  
  15. local tArgs = {...}
  16.  
  17. if type(tArgs[1]) ~= "string" then
  18.     printError("map_name: string expected")
  19.     printUsage()
  20.     return
  21. end
  22. starNav.setMap(tArgs[1])
  23.  
  24. for i = 2, 4 do
  25.     if tonumber(tArgs[i]) then
  26.         tArgs[i] = tonumber(tArgs[i])
  27.     else
  28.         printError("argument "..i.." must be a valid coordinate")
  29.         printUsage()
  30.         return
  31.     end
  32. end
  33.  
  34. local maxDistance
  35. if tArgs[5] ~= nil then
  36.     if tonumber(tArgs[5]) then
  37.         print("setting max_distance to: ", tArgs[5])
  38.         maxDistance = tonumber(tArgs[5])
  39.     else
  40.         printError("max_distance: number expected")
  41.         printUsage()
  42.         return
  43.     end
  44. end
  45.  
  46. print("going to coordinates = ", tArgs[2], ",", tArgs[3], ",", tArgs[4])
  47. local ok, err = starNav.goto(tArgs[2], tArgs[3], tArgs[4], maxDistance)
  48. if not ok then
  49.     printError("navigation failed: ", err)
  50. else
  51.     print("succesfully navigated to coordinates")
  52. end
RAW Paste Data