oblinger

GPS v2.0

Mar 27th, 2014
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.94 KB | None | 0 0
  1. --GPS v1.2
  2. --SAVE AS "mygps"
  3.  
  4.  
  5. tArgs = {...}
  6.  
  7. function autoUpdate()
  8. offv = fs.open("mygps","r")
  9. onv = http.get("http://pastebin.com/raw.php?i=NZdC82A2")
  10.  
  11.  
  12. if offv.readAll() ~= onv.readAll() then
  13. shell.run("clear")
  14. offv.close()
  15. print("Would you like to updaye (y/n)")
  16.  
  17. if read() == "y" then
  18. print("Okay Updating...")
  19.  
  20. print("Downloading newer version")
  21.  
  22. shell.run("pastebin get NZdC82A2 mygpsUPDATE")
  23.  
  24. print("Downloaded!")
  25. print("Deleting older version")
  26.  
  27. fs.delete("mygps")
  28.  
  29. print("Deleted!")
  30. print("Finishing...")
  31.  
  32. fs.move("mygpsUPDATE","mygps")
  33. shell.run()
  34. print("Done Updating!")
  35. error()
  36. end
  37. end
  38. end
  39.  
  40. autoUpdate()
  41. currentLab = os.getComputerLabel()
  42.  
  43. if tArgs[1] == nil and fs.isDir("bases") == true then
  44. print("Usage: mygps <location/add/delete/help>")
  45. error()
  46. end
  47.  
  48. if tArgs[1] == "add" then
  49. shell.run("clear")
  50.  
  51. print("Name of area/base?")
  52. name = read()
  53.  
  54. shell.run("clear")
  55.  
  56. print("What is the x cordinate?")
  57.  
  58. xcord = read()
  59. shell.run("clear")
  60.  
  61. print("What is the y cordinate?")
  62. ycord = read()
  63. shell.run("clear")
  64.  
  65. print("What is the z cordinate?")
  66. zcord = read()
  67. shell.run("clear")
  68.  
  69. repeat
  70. print("Is this correct? (y/n)")
  71. print("Area Name: "..name)
  72. print("X Cord: "..xcord)
  73. print("Y Cord: "..ycord)
  74. print("Z Cord: "..zcord)
  75.  
  76. input = read()
  77.  
  78. if input == "y" then
  79. baseFile = fs.open("bases/"..tostring(name),"w")
  80. baseFile.writeLine(tostring(xcord))
  81. baseFile.writeLine(tostring(ycord))
  82. baseFile.writeLine(tostring(zcord))
  83. baseFile.close()
  84. shell.run("clear")
  85. print("Okay! Area created!")
  86. elseif input == "n" then
  87. shell.run("clear")
  88. print("Okay! Area not created!")
  89. end
  90. until input == "n" or input == "y"
  91. error()
  92. end
  93.  
  94. if tArgs[1] == "delete" then
  95. shell.run("clear")
  96.  
  97. print("Name of area/base?")
  98. name = read()
  99.  
  100. if fs.exists("bases/"..name) == true then
  101. shell.run("clear")
  102. print("Are you sure you want to delete the location "..name.."? (y/n)")
  103.  
  104. input = read()
  105.  
  106. if input == "y" then
  107. fs.delete("bases/"..name)
  108. shell.run("clear")
  109. print("Deleted!")
  110. error()
  111. elseif input == "n" then
  112. print("Deletion canceled!")
  113. error()
  114. end
  115.  
  116. else
  117. printError("Location not found")
  118. error()
  119. end
  120. end
  121.  
  122.  
  123.  
  124.  
  125. if fs.isDir("bases") == false then
  126. shell.run("clear")
  127. print("Bases directory does no exist.")
  128. print("Would you like to make one? (y/n)")
  129.  
  130. input = read()
  131.  
  132. if input == "y" then
  133. shell.run("clear")
  134. print("Creating directory...")
  135. fs.makeDir("bases")
  136. baseFile = fs.open("bases/example","w")
  137. baseFile.writeLine("--This is the format--")
  138. baseFile.writeLine("(The x Cord) -369")
  139. baseFile.writeLine("(The y Cord) 52")
  140. baseFile.writeLine("(The z Cord) 869")
  141. baseFile.close()
  142. shell.run("clear")
  143. print("Done! Type <where add> to add a location")
  144. error()
  145. else
  146. print("Directory is required! Goodbye!")
  147. error()
  148. end
  149. end
  150.  
  151. if fs.exists("bases/"..tArgs[1]) == true then
  152. data = fs.open("bases/"..tArgs[1],"r")
  153. x = data.readLine()
  154. y = data.readLine()
  155. z = data.readLine()
  156. data.close()
  157. else
  158. printError("Location not recorded")
  159. error()
  160. end
  161.  
  162. base = vector.new(x,y,z)
  163.  
  164. current = vector.new(gps.locate()):round()
  165.  
  166. path = current-base
  167.  
  168.  
  169. function go()
  170. while true do
  171. shell.run("clear")
  172. print("To get to "..tArgs[1].."...")
  173.  
  174. current = vector.new(gps.locate()):round()
  175.  
  176. path = current-base
  177.  
  178.  
  179. if path.x > 1 then
  180. print("Go "..(path.x).." Blocks West")
  181. xP = ((path.x).." Blocks West")
  182. elseif path.x < -1 then
  183. print("Go "..math.abs(path.x).." Blocks East")
  184. xP = (math.abs(path.x).. " Blocks East")
  185. else
  186. xP = (" ")
  187. end
  188.  
  189. if path.z > 1 then
  190. print("Go "..path.z.." Blocks North")
  191. if xP ~= " " then
  192. os.setComputerLabel("Go "..(path.z).." Blocks North and "..xP)
  193. elseif xP == " " then
  194. os.setComputerLabel("Go "..(path.z).." Blocks North "..xP)
  195. end
  196. elseif path.z < -1 then
  197. print("Go "..math.abs(path.z).." Blocks South")
  198. if xP ~= " " then
  199. os.setComputerLabel("Go "..math.abs(path.z).." Blocks South and "..xP)
  200. elseif xP == " " then
  201. os.setComputerLabel("Go "..math.abs(path.z).." Blocks South "..xP)
  202. end
  203. else
  204. os.setComputerLabel("Go "..xP)
  205. end
  206.  
  207. if math.abs(path.x) < 5 and math.abs(path.z) < 5 then
  208. shell.run("clear")
  209. print("You are at the location!")
  210. os.setComputerLabel("You are at the location!")
  211. sleep(.5)
  212. os.setComputerLabel(currentLab)
  213. error()
  214. end
  215.  
  216.  
  217.  
  218. print()
  219. print("The cordinates are "..x.." "..y.." "..z)
  220.  
  221. sleep(.1)
  222. end
  223. end
  224.  
  225. function exit()
  226. event,p1,p2,p3 = os.pullEvent()
  227.  
  228. if key.getName(p1) == "t" and event == "key" then
  229. os.setComputerLabel(currentLab)
  230. shell.run("clear")
  231. print("Canceled")
  232. end
  233. end
  234.  
  235. parallel.waitForAny(go(),exit())
  236.  
  237. os.setComputerLabel(currentLab)
Advertisement
Add Comment
Please, Sign In to add comment