oblinger

How far

Mar 21st, 2014
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.13 KB | None | 0 0
  1. tArgs = {...}
  2.  
  3. if tArgs[1] == nil and fs.isDir("bases") == true then
  4. print("Usage: Where <location/add/delete/help>")
  5. error()
  6. end
  7.  
  8. if tArgs[1] == "add" then
  9. shell.run("clear")
  10.  
  11. print("Name of area/base?")
  12. name = read()
  13.  
  14. shell.run("clear")
  15.  
  16. print("What is the x cordinate?")
  17. xcord = read()
  18. shell.run("clear")
  19.  
  20. print("What is the y cordinate?")
  21. ycord = read()
  22. shell.run("clear")
  23.  
  24. print("What is the z cordinate?")
  25. zcord = read()
  26. shell.run("clear")
  27.  
  28. repeat
  29. print("Is this correct? (y/n)")
  30. print("Area Name: "..name)
  31. print("X Cord: "..xcord)
  32. print("Y Cord: "..ycord)
  33. print("Z Cord: "..zcord)
  34.  
  35. input = read()
  36.  
  37. if input == "y" then
  38. baseFile = fs.open("bases/"..tostring(name),"w")
  39. baseFile.writeLine(tostring(xcord))
  40. baseFile.writeLine(tostring(ycord))
  41. baseFile.writeLine(tostring(zcord))
  42. baseFile.close()
  43. shell.run("clear")
  44. print("Okay! Area created!")
  45. elseif input == "n" then
  46. shell.run("clear")
  47. print("Okay! Area not created!")
  48. end
  49. until input == "n" or input == "y"
  50. error()
  51. end
  52.  
  53. if tArgs[1] == "delete" then
  54. shell.run("clear")
  55.  
  56. print("Name of area/base?")
  57. name = read()
  58.  
  59. if fs.exists("bases/"..name) == true then
  60. shell.run("clear")
  61. print("Are you sure you want to delete the location "..name.."? (y/n)")
  62.  
  63. input = read()
  64.  
  65. if input == "y" then
  66. fs.delete("bases/"..name)
  67. shell.run("clear")
  68. print("Deleted!")
  69. error()
  70. elseif input == "n" then
  71. print("Deletion canceled!")
  72. error()
  73. end
  74.  
  75. else
  76. printError("Location not found")
  77. error()
  78. end
  79. end
  80.  
  81.  
  82.  
  83.  
  84.  
  85.  
  86.  
  87.  
  88. if fs.isDir("bases") == false then
  89. shell.run("clear")
  90. print("Bases directory does no exist.")
  91. print("Would you like to make one? (y/n)")
  92.  
  93. input = read()
  94.  
  95. if input == "y" then
  96. shell.run("clear")
  97. print("Creating directory...")
  98. fs.makeDir("bases")
  99. baseFile = fs.open("bases/example","w")
  100. baseFile.writeLine("--This is the format--")
  101. baseFile.writeLine("(The x Cord) -369")
  102. baseFile.writeLine("(The y Cord) 52")
  103. baseFile.writeLine("(The z Cord) 869")
  104. baseFile.close()
  105. shell.run("clear")
  106. print("Done! Type <where add> to add a location")
  107. error()
  108. else
  109. print("Directory is required! Goodbye!")
  110. error()
  111. end
  112. end
  113.  
  114. if fs.exists("bases/"..tArgs[1]) == true then
  115. data = fs.open("bases/"..tArgs[1],"r")
  116. x = data.readLine()
  117. y = data.readLine()
  118. z = data.readLine()
  119. data.close()
  120. else
  121. printError("Location not recorded")
  122. error()
  123. end
  124.  
  125. base = vector.new(x,y,z)
  126.  
  127. current = vector.new(gps.locate()):round()
  128.  
  129. path = current-base
  130.  
  131. shell.run("clear")
  132.  
  133. print("To get to "..tArgs[1].."...")
  134.  
  135. if path.x > 30 then
  136. print("Go "..path.x.." Blocks West")
  137. elseif path.x < -30 then
  138. print("Go "..math.abs(path.x).." Blocks East")
  139. end
  140.  
  141. if path.z > 30 then
  142. print("Go "..path.z.." Blocks North")
  143. elseif path.z < -30 then
  144. print("Go "..math.abs(path.z).." Blocks South")
  145. end
  146.  
  147. if math.abs(path.x) < 30 and math.abs(path.z) < 30 then
  148. print("You are at the location!")
  149. end
  150.  
  151. print()
  152. print("The cordinates are "..x.." "..y.." "..z)
Advertisement
Add Comment
Please, Sign In to add comment