Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- term.clear()
- term.setCursorPos(1,1) --Initiate the screen
- local homeLoc = {}
- print("Do you want to set your home position? Y/N")
- local setHome = read()
- if setHome == "Y" or setHome == "y" or setHome == "yes" then
- term.clear()
- local h = fs.open(".agpshome", "w")
- local newHome = {}
- local newHome = {gps.locate(1)} --Attempt to locate with gps to make newHome.
- if #newHome < 3 then
- print("GPS Signal Unavailable.")
- print("Please set manually. Input in order: X, Y, Z.") --Read inputs into newHome.
- newHome[1] = read()
- newHome[2] = read()
- newHome[3] = read()
- end
- h.write(textutils.serialize(newHome))
- h.close()
- end
- if fs.exists(".agpshome") then
- local h = fs.open(".agpshome", "r")
- homeLoc = textutils.unserialize(h.readAll())
- h.close()
- end
- while true do
- term.clear()
- term.setCursorPos(1,1)
- local loc = {gps.locate(1)} --Attempt to locate with gps, timeout 1 second.
- local sleepTime = 0.5
- if #loc < 3 then
- print("GPS Signal Unavailable.")
- sleepTime = 2
- else
- print("Location:")
- print("X: "..loc[1])
- print("Y: "..loc[2])
- print("Z: "..loc[3])
- end
- if #homeLoc > 1 then
- print("Home Location:")
- print("X: "..homeLoc[1])
- print("Y: "..homeLoc[2])
- print("Z: "..homeLoc[3])
- print("Distances from Home:")
- local homeVector = vector.new(homeLoc[1], homeLoc[2], homeLoc[3])
- local locVector = vector.new(loc[1], loc[2], loc[3])
- local homeDistance = locVector - homeVector --Use vector math to calculate distance
- print("X: "..homeDistance.x)
- print("Y: "..homeDistance.y)
- print("Z: "..homeDistance.z)
- end
- sleep(sleepTime)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement