frostthejack

RiMQuarry

Sep 23rd, 2013
352
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --this is a simple redstone in motion
  2. --quarry script and can be used
  3. --for many purposes
  4. --your startup file should read
  5. -- first line
  6. -- sleep(4)
  7. --second line
  8. -- shell.run("this script")
  9. -- you can reduce the sleep time but
  10. -- i dont recomend anything less then 2
  11.  
  12.  
  13. -- these are for direction
  14. local down = 0
  15. local up = 1
  16. local north = 2
  17. local south = 3
  18. local west = 4
  19. local east = 5
  20.  
  21. -- function to read from file
  22. function readFile(filename)
  23.   local rv
  24.   local h = fs.open(filename, "r")
  25.   if h then
  26.     rv = h.readLine()
  27.     h.close()
  28.   end
  29.   return rv
  30. end
  31.  
  32. --function to save to file
  33. function variableSave(fileName, variable)
  34.     h = fs.open(fileName, "w")
  35.     h.write(variable)
  36.     h.close()
  37. end
  38.  
  39. -- lets check if we are already doing something
  40. if
  41. fs.exists("count")
  42. then
  43. count = readFile("count")
  44. distance = readFile("distance")
  45. direction = readFile("direction")
  46.  
  47. else
  48. -- looks like we are not doing anything yet
  49. -- what do we want to do
  50.  
  51. while true do
  52. -- how many blocks to dig
  53. print("How far shall i dig master?")
  54. distance = read()
  55. distance = tonumber(distance)
  56. if
  57. type(distance) == "number"
  58. then
  59.  
  60. variableSave("distance", distance)
  61.  
  62. break
  63. else
  64. -- a number was not entered
  65. print("I am terribly sorry sir but that is not a number")
  66. end
  67. end
  68.  
  69. while true do
  70. -- which direction we going
  71. print("what direction")
  72. direction = read()
  73. if
  74. -- list of choices
  75. (direction == "down") or
  76. (direction == "up") or
  77. (direction == "north") or
  78. (direction == "south") or
  79. (direction == "west") or
  80. (direction == "east")
  81. then
  82.  
  83. variableSave("direction", direction)
  84.  
  85. print("You have 10 seconds to get off the rig")
  86. sleep(10)
  87. break
  88. else
  89.  
  90. -- entered an incorrect direction
  91. print("not a correct direction")
  92. end
  93. end
  94.  
  95. --create the count file then continue
  96. variableSave("count", "0")
  97. count = 0
  98.  
  99. end
  100.  
  101.  
  102.  
  103. -- check count file to see how many
  104. -- times we have moved in chosen
  105. -- direction
  106. if
  107. count == distance
  108. then
  109. -- done with moving delete count file
  110. -- to start over
  111. print("quarry done")
  112. fs.delete("count")
  113. else
  114. -- we are not done move in direction
  115. -- then add one to count and start over
  116. drive = peripheral.wrap("top")
  117. drive.move(direction, false, false)
  118. count = count + "1"
  119. variableSave("count", count)
  120. end
Advertisement
Add Comment
Please, Sign In to add comment