Advertisement
hohserg

05_navigation.lua

Jan 3rd, 2020
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.67 KB | None | 0 0
  1. local component = require("component")
  2.  
  3. local original_invoke=component.invoke
  4. component.invoke=function(address, method, ...)
  5.     if component.type(address)=="navigation" and method=="getPosition" then
  6.         local x,y,z=original_invoke(address, method, ...)
  7.         if not x then
  8.             local wp = original_invoke(address,"findWaypoints",... or 400)[1]
  9.             if wp then
  10.                 local nums=wp.label:gmatch("%-?%d+")
  11.                 x=nums()
  12.                 y=nums()
  13.                 z=nums()
  14.                 return x+wp.position[1]+0.5,y+wp.position[2]+0.5,z+wp.position[3]+0.5
  15.             else
  16.                 return nil,"out of range","waypoints not found"
  17.             end
  18.         else
  19.             return x,y,z
  20.         end
  21.     else
  22.         return original_invoke(address, method, ...)
  23.     end
  24. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement