666WTF666

turtle

Jun 13th, 2012
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.79 KB | None | 0 0
  1. turncheck = 0
  2. movecheck = 0
  3. count = 0
  4. write("Szerokosc : ")
  5. width = read()
  6. widthmax = tonumber(width)
  7. write("Dlugosc : ")
  8. length = read()
  9. lengthmax = tonumber(length)
  10. write("Wysokosc : ")
  11. height = read()
  12. heightmax = tonumber(height)
  13. total = Szerokosc * dlugosc * wysokosc
  14.  
  15.  
  16.  
  17. function positionCorrection() -- If the position goes outside the range, it will continue on the other side for example : position["width"] == 4 and there is no option 4, then it will go to option 1 and if position["width"] < 1 then it will go in this case to option number 3.
  18. local height = table.getn(text)
  19. local width = 0
  20. if position["height"] < 1 then position["height"] = height elseif position["height"] > height then position["height"] = 1 end
  21. for i=1, string.len(options[position["height"]]), 1 do
  22. if string.sub(options[position["height"]], i, i) == "|" then
  23. width = width+1
  24. end
  25. end
  26. if position["width"] < 1 then position["width"] = width elseif position["width"] > width then position["width"] = 1 end
  27. end
  28.  
  29. function controller() -- This show the text and let's see what option is selected and answered.
  30. term.clear()
  31. if error ~= "" then
  32. print(error.."\n")
  33. end
  34.  
  35. for i=1, table.getn(text), 1 do
  36. if position["height"] == i then write("> ") end
  37. write(text[i] .. "\n ")
  38. local optioncheck = 0
  39. local test = 0
  40. local optionamount = 1
  41. while string.sub(options[i], optioncheck, (optioncheck+1)) ~= "" do
  42. if string.sub(options[i], optioncheck, optioncheck) == "|" then
  43. if answers[i] == optionamount then
  44. write("(") -- If the option is between "([option])" then it means that the option is answered.
  45. end
  46.  
  47. if optionamount == position["width"] and i == position["height"] then
  48. write("-"..string.sub(options[i], test, (optioncheck-1)).."-") -- If the option is between "-[option]-" then it means it's selected.
  49. else
  50. write(string.sub(options[i], test, (optioncheck-1)))
  51. end
  52.  
  53. if answers[i] == optionamount then
  54. write(")")
  55. end
  56.  
  57. if optioncheck ~= string.len(options[i]) then
  58. write("|")
  59. end
  60.  
  61. test = optioncheck +1
  62. optionamount = optionamount + 1
  63. end
  64. optioncheck = optioncheck +1
  65. end
  66. print("")
  67. end
  68. end
  69.  
  70. function complete() -- Checks if every question is answered, so yes, it will continue to the program.
  71. local check = 0
  72. for a=1, table.getn(text), 1 do
  73. if answers[a] ~= nil then check= check +1 end
  74. end
  75. if check == (table.getn(text)-1) then
  76. return true
  77. else
  78. error = "You don't have answered all questions!"
  79. return false
  80. end
  81. end
  82.  
  83. controller()
  84. whilecheck = 1
  85. while true do -- Check for input from keyboard
  86. whilecheck = whilecheck + 1
  87. detect, key = os.pullEvent()
  88. if detect == "key" and key == keys["right"] then
  89. position["width"] = position["width"] +1
  90. positionCorrection()
  91. end
  92.  
  93. if detect == "key" and key == keys["left"] then
  94. position["width"] = position["width"] -1
  95. positionCorrection()
  96. end
  97.  
  98. if detect == "key" and key == keys["up"] then
  99. position["height"] = position["height"] -1
  100. positionCorrection()
  101. end
  102.  
  103. if detect == "key" and key == keys["down"] then
  104. position["height"] = position["height"] +1
  105. positionCorrection()
  106. end
  107.  
  108. if detect == "key" and key == keys["enter"] then
  109. if position["height"] == table.getn(text) then
  110. if complete() then
  111. break
  112. end
  113. else
  114. answers[position["height"]] = position["width"]
  115. end
  116. end
  117. controller()
  118. end
  119. term.clear()
  120. -- Still have more questions? Send me a message in youtube to the username : Maarten580
  121.  
  122. type = answers[1]
  123. buildcheck = answers[2]
  124.  
  125. function drop()
  126. for i=3,9,1 do
  127. if turtle.getItemSpace(i) == 0 then
  128. turtle.select(i)
  129. turtle.drop()
  130. turtle.select(2)
  131. end
  132. end
  133. end
  134.  
  135. function reset(width)
  136. if turncheck == 0 then
  137. turtle.turnLeft()
  138. sleep(0.2)
  139. turtle.turnLeft()
  140. sleep(0.2)
  141. for i=0,lengthmax,1 do
  142. dig()
  143. end
  144. end
  145. turtle.turnLeft()
  146. sleep(0.2)
  147. for i=0,(width-1),1 do
  148. dig()
  149. end
  150. sleep(0.2)
  151. turtle.turnLeft()
  152. turncheck = 0
  153. end
  154.  
  155. function dig(forward)
  156. if type == 1 then
  157. if turtle.detect() == true then
  158. turtle.dig()
  159. drop()
  160. sleep(0.2)
  161. turtle.forward()
  162. else
  163. turtle.forward()
  164. end
  165. else
  166. if turtle.detect() then
  167. turtle.select(1)
  168. if turtle.compare() ~= true then
  169. turtle.dig()
  170. if forward == true then
  171. turtle.forward()
  172. end
  173. drop()
  174. else
  175. while turtle.compare() == true do
  176. turtle.select(2)
  177. turtle.dig()
  178. turtle.select(1)
  179. drop()
  180. sleep(1)
  181. end
  182. end
  183. turtle.select(2)
  184. sleep(0.2)
  185. elseif forward == true then
  186. turtle.forward()
  187. end
  188. end
  189. end
  190.  
  191. function build(w, l, h)
  192. term.clear()
  193. count=count+1
  194. print("Width : "..w)
  195. print("Height : "..h)
  196. print("Length : "..l.."\n")
  197. print("Count : ".... " razem : "..razem)
  198. print("Completed : "..((count / total)*100).."%")
  199. print(buildcheck)
  200. if buildcheck == 1 then
  201. if h == heightmax then
  202. turtle.select(2)
  203. if turtle.detectDown() == false then
  204. turtle.placeDown()
  205. end
  206. elseif (heightmax - (h-1)) == heightmax then
  207. if turtle.detectUp() == false then
  208. turtle.placeUp()
  209. end
  210. end
  211.  
  212. if (w) == 1 then
  213. turtle.select(2)
  214. if movecheck == 0 then
  215. turtle.turnLeft()
  216. sleep(0.2)
  217. if turtle.detect() == false then
  218. turtle.place()
  219. end
  220. turtle.turnRight()
  221. sleep(0.2)
  222. else
  223. turtle.turnRight()
  224. sleep(0.2)
  225. if turtle.detect() == false then
  226. turtle.place()
  227. end
  228. turtle.turnLeft()
  229. sleep(0.2)
  230. end
  231. end
  232.  
  233. if (w) == widthmax then
  234. turtle.select(2)
  235. if movecheck == 0 then
  236. turtle.turnRight()
  237. sleep(0.2)
  238. if turtle.detect() == false then
  239. turtle.place()
  240. end
  241. turtle.turnLeft()
  242. sleep(0.2)
  243. else
  244. turtle.turnLeft()
  245. sleep(0.2)
  246. if turtle.detect() == false then
  247. turtle.place()
  248. end
  249. turtle.turnRight()
  250. sleep(0.2)
  251. end
  252. end
  253. end
  254. end
  255.  
  256. function turn()
  257. if turncheck == 0 then
  258. turtle.turnLeft()
  259. sleep(0.2)
  260. dig()
  261. sleep(0.2)
  262. turtle.turnLeft()
  263. turncheck = 1
  264. print("left")
  265. else
  266. turtle.turnRight()
  267. sleep(0.2)
  268. dig()
  269. sleep(0.2)
  270. turtle.turnRight()
  271. turncheck = 0
  272. print("right")
  273. end
  274. end
  275.  
  276. function hmove()
  277. if movecheck == 0 then
  278. turtle.turnRight()
  279. sleep(0.2)
  280. dig(true)
  281. sleep(0.2)
  282. turtle.turnLeft()
  283. else
  284. turtle.turnLeft()
  285. sleep(0.2)
  286. dig(true)
  287. sleep(0.2)
  288. turtle.turnRight()
  289. end
  290. end
  291.  
  292. function vmove(direction)
  293. if direction == "down" then
  294. if turtle.detectDown() then
  295. turtle.digDown("down")
  296. drop()
  297. sleep(0.2)
  298. turtle.down()
  299. else
  300. turtle.down()
  301. end
  302. elseif direction == "up" then
  303. if turtle.detectUp() then
  304. turtle.digUp()
  305. drop()
  306. sleep(0.2)
  307. turtle.up()
  308. else
  309. turtle.up()
  310. end
  311. end
  312. end
  313.  
  314. if type == 1 then
  315. heightmax = heightmax - 1
  316. widthmax = widthmax -1
  317. lengthmax = lengthmax -2
  318. for height=0,heightmax,1 do
  319. for width=0,widthmax,1 do
  320. for length=0,lengthmax,1 do
  321. dig()
  322. build(width, length, height)
  323. end
  324. if width ~= widthmax then
  325. turn()
  326. build(width, length, height)
  327. end
  328. end
  329. reset(widthmax)
  330. if heightmax ~= height then
  331. vmove("down")
  332. build(width, length, height)
  333. end
  334. end
  335. build(width, length, height)
  336. else
  337. width = 2
  338. for length=1,lengthmax,1 do
  339. for height=2,heightmax,1 do
  340. vmove("up")
  341. end
  342. dig()
  343. for height=1,heightmax,1 do
  344. dig()
  345. build((width-1), length, height)
  346. for width=2,widthmax,1 do
  347. hmove()
  348. dig()
  349. build((width), length, height)
  350. end
  351.  
  352. if height ~= heightmax then
  353. vmove("down")
  354. elseif length ~= lengthmax then
  355. dig(true)
  356. end
  357.  
  358. if movecheck == 0 then
  359. movecheck = 1
  360. else
  361. movecheck = 0
  362. end
  363. end
  364. end
  365. end
  366. sleep(2)
  367. term.clear()
  368. print("Kopanie Skonczone")
Advertisement
Add Comment
Please, Sign In to add comment