joppeaa

Quarrymachine_master.lua

Jan 3rd, 2021
300
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.29 KB | None | 0 0
  1. ---Variables
  2. diskdrive = 4
  3. floppy = 5
  4. turtleslot = 1
  5. fuel = 3
  6. loot = 2
  7. ---------------------
  8.  
  9.  
  10. rednet.open("left")
  11. turtle.select(1)
  12.  
  13. print("Slots: ","Turtle1","Loot2", "Fuel3", "Diskdrive4", "Floppy5" )
  14. print("Voer het aantal turtles in: ")
  15.  
  16. turtles = read()
  17. restturtle = turtles
  18. turtleID = turtles
  19.  
  20. print("Voer de maximale afstand in: ")
  21. maxdis = read()
  22.  
  23. print("Welke hoogte wil je beginnen?")
  24. depth = read()
  25.  
  26. function movetodepth()
  27.    
  28.     startheight = 1
  29.     local blok,type = turtle.inspectDown()
  30.     while type.name ~= ("minecraft:bedrock") do
  31.         turtle.digDown()
  32.         turtle.down()    
  33.         startheight = startheight + 1
  34.         blok,type = turtle.inspectDown()
  35.     end
  36.    
  37.     print("Arrived at bedrock")
  38.     print("Startheight is: ", startheight)
  39.     diepte = 0
  40.     for d = 0,depth do
  41.         turtle.digUp()
  42.         turtle.up()
  43.     end
  44.     print("Arrived at depth")
  45.     for v = 6, 16 do
  46.         turtle.select(v)
  47.         turtle.drop()
  48.     end
  49.     turtle.select(1)
  50. end
  51.  
  52. function movefromdepth()
  53.     upheight = startheight - depth
  54.     for i = 1, startheight do
  55.         turtle.up()
  56.     end
  57. end
  58.  
  59.  
  60. function diskplaats()
  61.     if turtle.detectDown() then
  62.         turtle.up()
  63.     end
  64.        
  65.     select(diskdrive)
  66.         if not turtle.detectDown() then
  67.             turtle.select(diskdrive)
  68.             turtle.placeDown()
  69.            
  70.         end
  71.     turtle.select(floppy)
  72.     turtle.dropDown()
  73.    
  74.    
  75.    
  76.     if turtle.detect() then
  77.         turtle.dig()
  78.     end  
  79.    
  80.  
  81. end
  82.  
  83. function turtleplaats()
  84.        
  85.     turtle.select(turtleslot)
  86.     turtle.forward()
  87.     turtle.digUp()
  88.     turtle.placeUp()
  89.     turtle.digDown()
  90.     for i = 1, turtles do
  91.            
  92.           while turtle.detectDown() do
  93.                     sleep(0.2)
  94.                     turtle.detectDown()
  95.                     print("Waiting for turtle ",turtleID," to leave")
  96.           end    
  97.           turtle.select(1)                
  98.           turtle.suckUp(1)
  99.           turtle.placeDown()
  100.           turtle.select(loot)
  101.           turtle.dropDown(1)
  102.           turtle.select(fuel)
  103.           turtle.dropDown(1)
  104.           peripheral.call("bottom",'turnOn')
  105.            sleep(1.5)
  106.           rednet.open("left")            
  107.           rednet.broadcast(turtleID, maxdis)
  108.           turtleID = turtleID - 1
  109.      end    
  110. end                      
  111.  
  112. function finalturtlewait()
  113.     while not redstone.getInput("bottom") do
  114.         print("Waiting for go from final turtle")
  115.         sleep(1)
  116.     end
  117. end
  118.  
  119. function zooiruimen()
  120.     print("Alle slaven losgelaten, even opruimen")
  121.     turtle.select(1)
  122.     turtle.digUp()
  123.     turtle.back()
  124.     turtle.select(5)
  125.     turtle.suckDown()
  126.     turtle.select(4)
  127.     turtle.digDown()
  128.     turtle.down()
  129. end
  130.  
  131.  
  132.                        
  133. movetodepth()                                                            
  134. diskplaats()
  135. turtleplaats()
  136. finalturtlewait()
  137.        
  138. rednet.broadcast("go")
  139. zooiruimen()
  140.  
  141.  
  142.  
  143.  
  144. while true do
  145.  
  146.     print("Druk op A om de turtles terug te laten keren")
  147.     local event,key = os.pullEvent("key")
  148.     if key == keys.a then
  149.        
  150.         turtle.select(turtleslot)
  151.         turtle.digUp()
  152.         turtle.placeUp()
  153.         while true do      
  154.             print("De turtles komen terug")
  155.             rednet.broadcast("comeback")
  156.            
  157.            
  158.             if restturtle == 0 then
  159.                 turtle.digUp()
  160.                 movefromdepth()
  161.                 error("Alle turtles zijn geruimd, einde programma")
  162.                
  163.                
  164.             end        
  165.             if turtle.detect() then
  166.                
  167.                 turtle.select(loot)
  168.                 turtle.suck()
  169.                 turtle.select(fuel)
  170.                 turtle.suck()
  171.                 turtle.select(turtleslot)
  172.                 turtle.dig()
  173.                 turtle.dropUp()
  174.                 restturtle = restturtle - 1
  175.                 print("Resterende turtles: ", restturtle)
  176.             end
  177.            
  178.             sleep(0.5)
  179.         end
  180.     end
  181.    print("De turtles laten minen")
  182.    rednet.broadcast("go")      
  183.    sleep(2)
  184.    
  185. end
  186.  
  187.            
  188.                                                                                                                                    
  189.  
Add Comment
Please, Sign In to add comment