Advertisement
Guest User

Untitled

a guest
Apr 27th, 2015
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.98 KB | None | 0 0
  1. no = 0
  2. so = 0
  3. ea = 0
  4. we = 0
  5. x = 0
  6. z = 0
  7. total = 0
  8. t = 0
  9. tc = 0
  10. mon = peripherial.wrap("top")
  11.  
  12. --calculate progress
  13. function prog()
  14. if total = 0 then
  15. sleep(1)
  16. else
  17. tp = math.floor(tc/total)
  18. mon.setCursorPos(1,4)
  19. mon.clearLine()
  20. mon.write("Total Progress: ")
  21. mon.write(tp)
  22. tc = tc + 1
  23. end
  24. end
  25.  
  26. function reset()
  27. redstone.setBundledOutput("back", 2)
  28. sleep(1)
  29. redstone.setBundledOutput("back", 0)
  30. sleep(5)
  31. end
  32.  
  33.  
  34. function north()
  35. redstone.setBundledOutput("back", 16384)
  36. sleep(5)
  37. redstone.setBundledOutput("back", 0)
  38. z = z - 1
  39. sleep(5)
  40. end
  41.  
  42. function south()
  43. redstone.setBundledOutput("back", 2048)
  44. sleep(1)
  45. redstone.setBundledOutput("back", 0)
  46. z = z + 1
  47. sleep(5)
  48. end
  49.  
  50. function west()
  51. redstone.setBundledOutput("back", 16)
  52. sleep(1)
  53. redstone.setBundledOutput("back", 0)
  54. x = x - 1
  55. sleep(5)
  56. end
  57.  
  58. function east()
  59. redstone.setBundledOutput("back", 8192)
  60. sleep(1)
  61. redstone.setBundledOutput("back", 0)
  62. x = x + 1
  63. sleep(5)
  64. end
  65.  
  66. function fireEW()
  67. redstone.setBundledOutput("back", 33)
  68. sleep(20)
  69. redstone.setBundledOutput("back", 0)
  70. sleep(5)
  71. end
  72.  
  73. function fireNS()
  74. redstone.setBundledOutput("back", 32776)
  75. sleep(20)
  76. redstone.setBundledOutput("back", 0)
  77. sleep(5)
  78. end
  79.  
  80.  
  81.  
  82. function rpos()
  83. mon.setCursorPos(1,1)
  84. mon.clearLine()
  85. mon.write("Rig current position:")
  86. mon.setCursorPos(1,2)
  87. mon.clearLine()
  88. mon.write("X: ")
  89. print("Enter X coordinate")
  90. x = tonumber(io.read())
  91. mon.write(x)
  92. mon.write(" Z: ")
  93. print("Enter Z coordinate")
  94. z = tonumber(io.read())
  95. mon.write(z)
  96. q2()
  97. end
  98.  
  99. function upos()
  100. mon.setCursorPos(1,2)
  101. mon.clearLine()
  102. mon.write("X: ")
  103. mon.write(x)
  104. mon.write(" Z: ")
  105. mon.write(z)
  106. end
  107.  
  108. function mdirn()
  109. nu = no
  110. for i = 1, no do
  111. print("North operations left: ")
  112. write(nu)
  113. prog()
  114. north()
  115. upos()
  116. fireEW()
  117. nu = nu - 1
  118. end
  119. no = 0
  120. end
  121.  
  122. function mdirs()
  123. local su = so
  124. for i = 1, so do
  125. print("South operations left: ")
  126. write(su)
  127. prog()
  128. south()
  129. upos()
  130. fireEW()
  131. su = su - 1
  132. end
  133. so = 0
  134. end
  135.  
  136. function mdire()
  137. local eu = ea
  138. for i = 1, ea do
  139. print("East operations left: ")
  140. write(eu)
  141. prog()
  142. east()
  143. upos()
  144. fireNS()
  145. eu = eu - 1
  146. end
  147. ea = 0
  148. end
  149.  
  150. function mdirw()
  151. local wu = we
  152. for i = 1, we do
  153. print("West operations left: ")
  154. write(wu)
  155. prog()
  156. west()
  157. upos()
  158. fireNS()
  159. wu = wu - 1
  160. end
  161. we = 0
  162. end
  163.  
  164. function w()
  165. print("Mine west how many times?")
  166. we = tonumber(io.read())
  167. print("Mining west ")
  168. write(we)
  169. if we == 1 then
  170. write(" time. ")
  171. else
  172. write(" times. ")
  173. end
  174. q3()
  175. end
  176.  
  177. function e()
  178. print("Mine east how many times?")
  179. ea = tonumber(io.read())
  180. print("Mining east ")
  181. write(ea)
  182. if ea == 1 then
  183. write(" time. ")
  184. else
  185. write(" times. ")
  186. end
  187. q3()
  188. end
  189.  
  190. function n()
  191. print("Mine north how many times?")
  192. no = tonumber(io.read())
  193. print("Mining north ")
  194. write(no)
  195. if no == 1 then
  196. write(" time. ")
  197. else
  198. write(" times. ")
  199. end
  200. end
  201.  
  202. function s()
  203. print("Mine south how many times?")
  204. so = tonumber(io.read())
  205. print("Mining south ")
  206. write(so)
  207. if so == 1 then
  208. write(" time. ")
  209. else
  210. write(" times. ")
  211. end
  212. end
  213.  
  214. function q1()
  215. print("Set rig position? y/n")
  216. local qe1 = io.read()
  217. if qe1 == "y" then
  218. rpos()
  219. elseif qe1 == "n" then
  220. q2()
  221. else
  222. print("Invalid character. Must be y/n")
  223. qe1 = "v"
  224. q1()
  225. end
  226. end
  227.  
  228. function q2()
  229. print("Mine which direction?")
  230. local qe2 = io.read()
  231. if qe2 == "north" then
  232. n()
  233. print("Accepted.")
  234. q3()
  235. elseif qe2 == "south" then
  236. s()
  237. print("Accepted.")
  238. q3()
  239. elseif qe2 == "east" then
  240. e()
  241. print("Accepted.")
  242. q3()
  243. elseif qe2 == "west" then
  244. w()
  245. print("Accepted.")
  246. q3()
  247. elseif qe2 == "cancel" then
  248. exit()
  249. else
  250. print("Invalid direction. Must be north")
  251. print("south west or east or cancel")
  252. qe2 = "v"
  253. q2()
  254. end
  255. end
  256.  
  257. function q3()
  258. print("Mine any aditional directions? y/n")
  259. local qe3 = io.read()
  260. if qe3 == "y" then
  261. q2()
  262. elseif qe3 == "n" then
  263. mine()
  264. else
  265. print("Invalid character. Must be y/n")
  266. q3()
  267. end
  268. end
  269.  
  270.  
  271.  
  272. function printloc()
  273. printer = peripheral.wrap("right")
  274. printer.newPage()
  275. printer.setPageTitle("RIG STOPPED AT")
  276. printer.write("X: ")
  277. printer.write(x)
  278. printer.write(" Z: ")
  279. printer.write(z)
  280. printer.endPage()
  281. print("Current location printout successful.")
  282. end
  283.  
  284.  
  285. function mine()
  286. print("Mining operation start.")
  287. total = no + we + ea + so
  288. if no > 0 then
  289. reset()
  290. sleep(3)
  291. north()
  292. mdirn()
  293. reset()
  294. elseif we > 0 then
  295. reset()
  296. sleep(3)
  297. west()
  298. mdirw()
  299. reset()
  300. elseif so > 0 then
  301. reset()
  302. sleep(3)
  303. south()
  304. mdirs()
  305. reset()
  306. elseif ea > 0 then
  307. reset()
  308. sleep(3)
  309. east()
  310. mdire()
  311. reset()
  312. else
  313. exit()
  314. end
  315. upos()
  316. printloc()
  317. end
  318.  
  319. q1()
  320.  
  321. reset()
  322.  
  323. print("Mining operation complete.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement