Matix-Media

Improved turtle program

Mar 20th, 2022 (edited)
731
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.13 KB | None | 0 0
  1. -- This Version
  2. -- 2.13 10/11/2014
  3. -- ChangeLogs
  4. -- 2.04 - Adding Left or Right Support
  5. -- 2.05 - Changing Lot Code For Some Stable And Cleaner Code
  6. -- 2.06 - Ops Forget Fuel Chcking Code after rewrtitting
  7. -- 2.07 - Woops My Bad i wrote back() not Back()
  8. -- 2.08 - Fixing Imputs
  9. -- 2.09 - Forget That i change remove line of code since i use local function now
  10. -- 2.10 - Minor error with back that it leave one block in wall
  11. --    Change: Torch spacing to 8 from 10
  12. -- 2.11 - Change: Right to left and Left to Right better understand
  13. -- 2.12 - Add Stop Code when item are gone
  14. -- 2.13 - i made big mistake i forget to end to new stop code
  15. -- ToDoList
  16. -- Add Code to place torch each time it starts
  17. -- Add Fuel Code so can know almost how much fuel you need
  18. -- Add second fuel slot if you go allout diggin
  19. -- Mabye add code that make turtle make new line of tunnels
  20.  
  21. --Local
  22. local distance = 0 -- How Far Did User Pick
  23. local chest = turtle.getItemCount(2) -- How many items are in slot 2 (chest)
  24. local ItemFuel = turtle.getItemCount(1) -- How many items are in slot 3 (Fuel)
  25. local MD = 3 -- How Many Blocks Apart From Each Mine
  26. local MineTimes = 0 -- If Multi Mines Are ON then This will keep Count
  27. local Fuel = 0 -- if 2 then it is unlimited no fuel needed
  28. local NeedFuel = 0 -- If Fuel Need Then 1 if not Then 0
  29. local Error = 0 -- 0 = No Error and 1 = Error
  30. local Way = 0 -- 0 = Left and 1 = Right
  31. local RowSpace = 0 -- The space between each row
  32.  
  33. --Checking
  34. local function Check()
  35.     if chest == 0 then
  36.         print("there are no chests")
  37.         Error = 1
  38.     else
  39.         print("There are chest in turtle")
  40.     end
  41.     if ItemFuel == 0 then
  42.         print("No Fuel Items")
  43.         Error = 1
  44.     else
  45.         print("there is fuel")
  46.     end
  47.     repeat
  48.         if turtle.getFuelLevel() == "unlimited" then
  49.             print("NO NEED FOR FUEL")
  50.             Needfuel = 0
  51.         elseif turtle.getFuelLevel() < 100 then
  52.             turtle.select(3)
  53.             turtle.refuel(1)
  54.             Needfuel = 1
  55.             ItemFuel = ItemFuel - 1
  56.         elseif NeedFuel == 1 then
  57.             Needfuel = 0
  58.         end
  59.     until NeedFuel == 0
  60. end
  61.  
  62. -- Recheck if user forget something turtle will check after 15 sec
  63. local function Recheck()
  64.     chest = turtle.getItemCount(2)
  65.     ItemFuel = turtle.getItemCount(1)
  66.     Error = 0
  67. end
  68.  
  69. --Mining
  70. local function ForwardM()
  71.     repeat
  72.         if turtle.detect() then
  73.             turtle.dig()
  74.         end
  75.         if turtle.forward() then -- sometimes sand and gravel and block and mix-up distance
  76.             TF = TF - 1
  77.         end
  78.         if turtle.detectUp() then
  79.             turtle.digUp()
  80.         end
  81.         turtle.select(3)
  82.         turtle.placeDown()
  83.         if turtle.getItemCount(16)>0 then -- If slot 16 in turtle has item slot 5 to 16 will go to chest
  84.             if chest > 0 then
  85.                 turtle.select(2)
  86.                 turtle.digDown()
  87.                 turtle.placeDown()
  88.                 chest = chest - 1
  89.                 for slot = 5, 16 do
  90.                     turtle.select(slot)
  91.                     turtle.dropDown()
  92.                     sleep(1.5)
  93.                 end
  94.                 turtle.select(5)
  95.             else
  96.                 print("turtle run out of chest")
  97.                 os.shutdown()
  98.             end
  99.         end
  100.         repeat
  101.             if turtle.getFuelLevel() == "unlimited" then
  102.                 print("NO NEED FOR FUEL")
  103.                 Needfuel = 0
  104.             elseif turtle.getFuelLevel() < 100 then
  105.                 turtle.select(1)
  106.                 turtle.refuel(1)
  107.                 Needfuel = 1
  108.                 ItemFuel = ItemFuel - 1
  109.             elseif ItemFuel == 0 then
  110.                 print("turtle run out of fuel")
  111.                 os.shutdown()
  112.             elseif NeedFuel == 1 then
  113.                 Needfuel = 0
  114.             end
  115.         until NeedFuel == 0
  116.     until TF == 0
  117. end
  118.  
  119. --Warm Up For Back Program
  120. local function WarmUpForBackProgram() -- To make turn around so it can go back
  121.     turtle.turnLeft()
  122.     turtle.turnLeft()
  123.     turtle.up()
  124. end
  125.  
  126. --Back Program
  127. local function Back()
  128.     repeat
  129.         if turtle.forward() then -- sometimes sand and gravel and block and mix-up distance
  130.             TB = TB - 1
  131.         end
  132.         if turtle.detect() then -- Sometimes sand and gravel can happen and this will fix it
  133.             if TB ~= 0 then
  134.                 turtle.dig()
  135.             end
  136.         end
  137.     until TB == 0
  138. end
  139.  
  140. -- Multimines Program
  141. local function MultiMines()
  142.     if Way == 1 then
  143.         turtle.turnLeft()
  144.         turtle.down()
  145.     else
  146.         turtle.turnRight()
  147.         turtle.down()
  148.     end
  149.     repeat
  150.         if turtle.detect() then
  151.             turtle.dig()
  152.         end
  153.         if turtle.forward() then
  154.             MD = MD - 1
  155.         end
  156.         if turtle.detectUp() then
  157.             turtle.digUp()
  158.         end
  159.     until MD == 0
  160.     if Way == 1 then
  161.         turtle.turnLeft()
  162.     else
  163.         turtle.turnRight()
  164.     end
  165.     if MineTimes == 0 then
  166.         print("Turtle is done")
  167.     else
  168.         MineTimes = MineTimes - 1
  169.     end
  170. end
  171.  
  172. -- Restart
  173. local function Restart()
  174.     TF = distance
  175.     TB = distance
  176.     MD = RowSpace
  177. end
  178.  
  179. -- Starting
  180. function Start()
  181.     repeat
  182.         ForwardM()
  183.         WarmUpForBackProgram()
  184.         Back()
  185.         MultiMines()
  186.         Restart()
  187.     until MineTimes == 0
  188. end
  189.  
  190. -- Start
  191. print("Hi there, welcome to Matix's improved turtle script.\n")
  192. print("How far will turtle go?")
  193. input = io.read()
  194. distance = tonumber(input)
  195. TF = distance
  196. TB = distance
  197. print("left or right?")
  198. print("0: Left\n1: Right")
  199. input2 = io.read()
  200. Way = tonumber(input2)
  201. print("How many rows will the turtle mine?")
  202. input3 = io.read()
  203. MineTimes = tonumber(input3)
  204. print("How much space should be left between each row?")
  205. print("1 = no space")
  206. RowSpace = tonumber(io.read())
  207. MD = RowSpace
  208. Check()
  209. if Error == 1 then
  210.     repeat
  211.         sleep(10)
  212.         Recheck()
  213.         Check()
  214.     until Error == 0
  215. end
  216. Start()
Advertisement
Add Comment
Please, Sign In to add comment