Advertisement
blunty666

netNav_goto

Dec 23rd, 2015
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.17 KB | None | 0 0
  1. local function printUsage()
  2.     print("Usage:")
  3.     print(fs.getName(shell.getRunningProgram()).." <remoteMap_name> <x_pos> <y_pos> <z_pos>")
  4.     print("<remoteMap_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. end
  7.  
  8. if not netNav then
  9.     if not os.loadAPI("netNav") then
  10.         error("could not load netNav API")
  11.     end
  12. end
  13.  
  14. for _, side in ipairs(redstone.getSides()) do
  15.     if peripheral.getType(side) == "modem" then
  16.         rednet.open(side)
  17.     end
  18. end
  19.  
  20. if not rednet.isOpen() then
  21.     error("could not open rednet")
  22. end
  23.  
  24. local tArgs = {...}
  25.  
  26. if type(tArgs[1]) ~= "string" then
  27.     printError("remoteMap_name: string expected")
  28.     printUsage()
  29.     return
  30. end
  31. netNav.setMap(tArgs[1], 30)
  32.  
  33. for i = 2, 4 do
  34.     if tonumber(tArgs[i]) then
  35.         tArgs[i] = tonumber(tArgs[i])
  36.     else
  37.         printError("argument "..i.." must be a valid coordinate")
  38.         printUsage()
  39.         return
  40.     end
  41. end
  42.  
  43. print("going to coordinates = ", tArgs[2], ",", tArgs[3], ",", tArgs[4])
  44. local ok, err = netNav.goto(tArgs[2], tArgs[3], tArgs[4])
  45. if not ok then
  46.     printError("navigation failed: ", err)
  47. else
  48.     print("succesfully navigated to coordinates")
  49. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement