Advertisement
Guest User

Tunnel V2.2.1 By Ninetainedo

a guest
Jul 6th, 2013
3,051
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 20.78 KB | None | 0 0
  1. -- Tunnel script V2.2 --
  2. -- By Ninetainedo -- NoFake Dev Team--
  3. -- Dig a tunnel and fills walls --
  4.  
  5. args = {...}
  6. local width, height, length = 3, 3, 10
  7. local config = false
  8.  
  9. if (#args == 1 and args[1] == "-c") then
  10.   config = true
  11. elseif #args ~= 1 then
  12.   shell.run("clear")
  13.   print("Usage : tunnel option\n")
  14.   print("Option can be :")
  15.   print("  -c to run in config mode.")
  16.   print("  -d to run in default mode.\n")
  17.   print("In default mode, it makes a 3x3x10 tunnel and fills walls, floor and ceiling.\nIt also empties itself and comes back when it needs blocks.")
  18.   return
  19. end
  20.  
  21. local name = "Tunnel"
  22. local side, x, y, z = 0, 0, 0, 0
  23. local moved = 0
  24. local a, b, c
  25. local blockSlotsToKeep = 8
  26. local slots = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}
  27. local goBackForCobble, goBackForEmpty, digOnly, sendOnRednet = true, true, false, true
  28. local fillCeiling, fillFloor, fillLeftWall, fillRightWall, fillBackWall = true, true, true, true, true
  29. local pos = "left"
  30. local percent, oldPercent = 0, -1
  31. local wTerm, hTerm = term.getSize()
  32. local screen = {}
  33. local messages = {}
  34. local percent = 50
  35. local msgLen = math.ceil(hTerm / 2) - 2
  36. local currentMsgIndex = 1
  37. local infos = { blocksDug = 0, blocksPlaced = 0}
  38. local p = 0
  39.  
  40. function main()
  41.   shell.run("clear")
  42.   if (config == true) then
  43.     configMode()
  44.   end
  45.  
  46.   if (sendOnRednet) then
  47.     rednet.open("right")
  48.   end
  49.  
  50.   screenQuery("init")
  51.   tell("Launching !")
  52.   checkBlock()
  53.   a = 0
  54.  
  55.   -- Boucle sur la longueur --
  56.   while (a < length) do
  57.     b = 0
  58.     if (side == 3) then
  59.       turnRight()
  60.     elseif (side == 1) then
  61.       turnLeft()
  62.     end
  63.     if (turtle.detect()) then dig() end
  64.     forward()
  65.    
  66.     -- Boucle de balayage vertical --
  67.     while (b < height) do
  68.       c = 0
  69.       if (side == 0 and pos == "left") then
  70.         turnLeft()
  71.       elseif (side == 0 and pos == "right") then
  72.         turnRight()
  73.       end
  74.       putBlock()
  75.       if (pos == "right") then
  76.         turnLeft()
  77.       elseif (pos == "left") then
  78.         turnRight()
  79.       end
  80.       if (side == 0 and pos == "right") then
  81.         turnLeft()
  82.       elseif (side == 0 and pos == "left") then
  83.         turnRight()
  84.       end
  85.      
  86.       -- Boucle de balayage horizontal --
  87.       while (c < width) do
  88.         if (c == width - 1) then
  89.           putBlock()
  90.         end
  91.         if (z == 0) then
  92.           putBlock("down")
  93.         end
  94.         if (z == height - 1) then
  95.           putBlock("up")
  96.         end
  97.        
  98.         if (not digOnly and fillBackWall and a == length - 1) then
  99.           if (pos == "left") then
  100.             turnLeft()
  101.           else
  102.             turnRight()
  103.           end
  104.           putBlock()
  105.           if (pos == "right") then
  106.             turnLeft()
  107.           else
  108.             turnRight()
  109.           end
  110.         end
  111.        
  112.         if (c < width - 1) then
  113.           if (turtle.detect()) then dig() end
  114.         end
  115.         if (z < height - 1) then
  116.           if (turtle.detectUp()) then dig("up") end
  117.         end
  118.         if (c < width - 1) then
  119.           forward()
  120.         end
  121.         c = c + 1
  122.         checkBlock()
  123.         checkInventory()
  124.         updatePercent()
  125.       end -- While y
  126.       if (z < height - 1) then
  127.         up()
  128.       end
  129.       if (pos == "left") then
  130.         pos = "right"
  131.       else
  132.         pos = "left"
  133.       end
  134.       b = b + 1
  135.     end -- While z
  136.     while (z ~= 0) do down() end
  137.   a = a + 1
  138.   end -- While x
  139.   goToPos(-1 * x, -1 * y, -1 * z, -1 * side, "szyx")
  140.   tell("Done !!")
  141.  
  142.   if (sendOnRednet) then
  143.     rednet.close("right")
  144.   end
  145. end
  146.  
  147. function updatePercent()
  148.   percent = math.floor(reMap(p, 0, length * width * height, 0, 100))
  149.   screenQuery("update", "progress", percent)
  150.   screenQuery("draw")
  151. end
  152.  
  153. function reMap(val, min1, max1, min2, max2)
  154.   local div = max1 - min1
  155.  
  156.   if (div == 0) then div = 1 end
  157.   return ((val - min1) * (max2 - min2) / div + min2)
  158. end
  159.  
  160. function screenQuery(query, ...)
  161.   local tArgs = {...}
  162.   local writeAtPos = function(message, x, y)
  163.     term.setCursorPos(x, y)
  164.     write(message)
  165.   end
  166.   local getCenteredX = function(message)
  167.     return math.ceil((wTerm / 2) - (#message / 2))
  168.   end
  169.   local writeInTable = function(message, x, y)
  170.     if (x + #message > wTerm) then
  171.       return false
  172.     end
  173.     for i = 1, #message do
  174.       screen[y][x + i - 1] = message:sub(i, i)
  175.     end
  176.     return true
  177.   end
  178.   local printProgressBar = function(percent)
  179.     local y = math.ceil(hTerm / 2 * 3 / 2)
  180.     local barPercent = reMap(percent, 0, 100, 4, wTerm - 2)
  181.     local a = 4
  182.  
  183.     screen[y][3] = '['
  184.     screen[y][wTerm - 2] = ']'
  185.     while (a < barPercent) do
  186.       screen[y][a] = '='
  187.       a = a + 1
  188.     end
  189.     writeInTable(tostring(percent).."%", getCenteredX(tostring(percent).."%") + 1, y + 1)
  190.   end
  191.  
  192.   if (query == "init") then
  193.     local mid = math.ceil(hTerm / 2)
  194.     for j = 1, hTerm do
  195.       screen[j] = {}
  196.       for i = 1, wTerm do
  197.         if ((i == 1 or i == wTerm) and (j == 1 or j == hTerm)) then
  198.           screen[j][i] = '+'
  199.         elseif (i == 1 or i == wTerm) then
  200.           screen[j][i] = '|'
  201.         elseif (j == 1 or j == hTerm) then
  202.           screen[j][i] = '-'
  203.         elseif (j == mid) then
  204.           screen[j][i] = '-'
  205.         else
  206.           screen[j][i] = ' '
  207.         end
  208.       end
  209.     end
  210.     printProgressBar(0)
  211.     for j = 1, msgLen do
  212.       messages[j] = ""
  213.     end
  214.     elseif (query == "draw") then
  215.       for j = 1, hTerm do
  216.         for i = 1, wTerm do
  217.           writeAtPos(screen[j][i], i, j)
  218.         end
  219.       end
  220.     elseif (query == "update" and tArgs[1] == "progress") then
  221.       printProgressBar(tArgs[2])
  222.     elseif (query == "update" and tArgs[1] == "message") then
  223.       messages[currentMsgIndex] = tArgs[2]
  224.       for j = 1, msgLen do
  225.         writeInTable(messages[j], 2, j + 1)
  226.       end
  227.       if (currentMsgIndex + 1 > msgLen)then
  228.         table.remove(messages, 1)
  229.         currentMsgIndex = msgLen
  230.       else
  231.         currentMsgIndex = currentMsgIndex + 1
  232.       end
  233.     end
  234. end
  235.  
  236. function checkInventory()
  237.   local count = 1
  238.  
  239.   if (goBackForEmpty and isInventoryFull()) then
  240.     tell("Need empty")
  241.     goToPos(-1 * x, -1 * y, -1 * z, -1 * side, "szyx")
  242.     turtle.turnLeft()
  243.     turtle.turnLeft()
  244.     for i = (digOnly and 1 or 2),16 do
  245.       turtle.select(i)
  246.       if (digOnly or count >= blockSlotsToKeep or not turtle.compareTo(1)) then
  247.         turtle.drop()
  248.       else
  249.         count = count + 1
  250.       end
  251.     end
  252.     turtle.select(1)
  253.     tell("Empty done !")
  254.     turtle.turnRight()
  255.     turtle.turnRight()
  256.     goToPos(x, y, z, side, "zyxs")
  257.   end
  258. end
  259.  
  260. function manageInventory()
  261.   local blockSlots = {}
  262.   local emptySlot = -1
  263.  
  264.   if (digOnly) then
  265.     return true
  266.   end
  267.   -- Superposition d'un maximum d'items --
  268.   for i, slot in ipairs(slots) do
  269.     turtle.select(slot)
  270.     if (turtle.getItemCount(slot) > 0) then
  271.       for j, slot2 in ipairs(slots) do
  272.         if (slot2 > slot) then
  273.           if (turtle.getItemSpace(slot) == 0) then
  274.             break
  275.           end
  276.           if (turtle.compareTo(slot2)) then
  277.             turtle.select(slot2)
  278.             turtle.transferTo(slot)
  279.             turtle.select(slot)
  280.           end
  281.         end
  282.       end
  283.     end
  284.   end
  285.  
  286.   -- On met tous les items le plus en haut à gauche possible --
  287.   for i, slot in ipairs(slots) do
  288.     if (turtle.getItemCount(slot) == 0) then
  289.       for j, slot2 in ipairs(slots) do
  290.         if (slot2 > slot and turtle.getItemCount(slot2) > 0) then
  291.           turtle.select(slot2)
  292.           turtle.transferTo(slot)
  293.           turtle.select(slot)
  294.           break
  295.         end
  296.       end
  297.     end
  298.   end
  299.  
  300.   -- Chargement des infos de l'inventaire pour la gestion des blocs de remplissage --
  301.   for i, slot in ipairs(slots) do
  302.     turtle.select(slot)
  303.     if (turtle.compareTo(1)) then
  304.       table.insert(blockSlots, slot)
  305.     end
  306.   end
  307.  
  308.   -- On cherche un slot vide --
  309.   for i, slot in ipairs(slots) do
  310.     if (not digOnly and slot > blockSlotsToKeep and turtle.getItemCount(slot) == 0) then
  311.       emptySlot = slot
  312.       break
  313.     end
  314.   end
  315.  
  316.   if (emptySlot == -1) then
  317.     return false
  318.   end
  319.   -- On supprime de la table le slot de référence --
  320.   table.remove(blockSlots, 1)
  321.   local blockSlotsLen = #blockSlots
  322.  
  323.   -- Pour chaque emplacement de block qu'on
  324.   -- veut "reserver", on y place de la block
  325.   -- s'il y en a ailleurs --
  326.   -- --
  327.   -- Ex : Si le slot 2 est vide alors que
  328.   -- blockslotsToKeep vaut 4, on va chercher
  329.   -- de la block dans les slots de 3 a 16 et,
  330.   -- si on en trouve, on va la mettre dans le
  331.   -- slot 2 --
  332.   for i = 2, blockSlotsToKeep do
  333.     turtle.select(i)
  334.     if (not turtle.compareTo(1) and turtle.getItemCount(i) > 0) then
  335.       if (blockSlotsLen > 0) then
  336.         slotTransfer(blockSlots[1], i, emptySlot)
  337.         table.remove(blockSlots, 1)
  338.         blockSlotsLen = blockSlotsLen - 1
  339.       else
  340.         break
  341.       end
  342.     end
  343.   end
  344. end
  345.  
  346. function slotTransfer(slotSrc, slotDest, slotEmpty)
  347.   local hasEmpty = false
  348.  
  349.   if (turtle.getItemCount(slotEmpty) > 0) then
  350.     turtle.select(slotEmpty)
  351.     turtle.drop()
  352.     hasEmpty = true
  353.   end
  354.   if (turtle.getItemCount(slotDest) == 0) then
  355.     turtle.select(slotSrc)
  356.     turtle.transferTo(slotDest)
  357.   else
  358.     turtle.select(slotDest)
  359.     turtle.transferTo(slotEmpty)
  360.     turtle.select(slotSrc)
  361.     turtle.transferTo(slotDest)
  362.     turtle.select(slotEmpty)
  363.     turtle.transferTo(slotSrc)
  364.   end
  365.   if (hasEmpty) then
  366.     turtle.suck()
  367.   end
  368. end
  369.  
  370. function isInventoryFull(var)
  371.   for i, slot in ipairs(slots) do
  372.     if (turtle.getItemCount(slot) == 0) then
  373.       return false
  374.     end
  375.   end
  376.   if (not var) then
  377.     manageInventory()
  378.     return isInventoryFull(true)
  379.   end
  380.   return true
  381. end
  382.  
  383. function putBlock(face)
  384.   turtle.select(1)
  385.  
  386.   if (digOnly) then
  387.     return
  388.   end
  389.  
  390.   if (face == nil) then
  391.     if ((side == 1 and fillRightWall) or (side == 3 and fillLeftWall) or (side == 0 and fillBackWall)) then
  392.       if (not turtle.detect()) then
  393.         while (not turtle.place()) do
  394.           turtle.attack()
  395.         end
  396.         infos.blocksPlaced = infos.blocksPlaced + 1
  397.       elseif (not turtle.compare()) then
  398.         dig()
  399.         while (not turtle.place()) do
  400.           turtle.attack()
  401.         end
  402.         infos.blocksPlaced = infos.blocksPlaced + 1
  403.       end
  404.     end
  405.   elseif (face == "up") then
  406.     if (fillCeiling) then
  407.       if (not turtle.detectUp()) then
  408.         while (not turtle.placeUp()) do
  409.           turtle.attackUp()
  410.         end
  411.         infos.blocksPlaced = infos.blocksPlaced + 1
  412.       elseif (not turtle.compareUp()) then
  413.         dig("up")
  414.         while (not turtle.placeUp()) do
  415.           turtle.attackUp()
  416.         end
  417.         infos.blocksPlaced = infos.blocksPlaced + 1
  418.       end
  419.     end
  420.   elseif (face == "down") then
  421.     if (fillFloor) then
  422.       if (not turtle.detectDown()) then
  423.         while (not turtle.placeDown()) do
  424.           turtle.attackDown()
  425.         end
  426.         infos.blocksPlaced = infos.blocksPlaced + 1
  427.       elseif (not turtle.compareDown()) then
  428.         dig("down")
  429.         while (not turtle.placeDown()) do
  430.           turtle.attackDown()
  431.         end
  432.         infos.blocksPlaced = infos.blocksPlaced + 1
  433.       end
  434.     end
  435.   end
  436. end
  437.  
  438. function readPrompt(prompt, mode, onError, onSuccess, needClear, stricly)
  439.   local value = nil
  440.  
  441.   while (value == nil) do
  442.     if (needClear) then
  443.       shell.run("clear")
  444.     end
  445.     write(prompt)
  446.     value = read()
  447.     if (mode == 1) then
  448.       value = tonumber(value)
  449.       if (value == nil or (stricly and value <= 0)) then
  450.         onError()
  451.         value = nil
  452.       end
  453.     elseif (mode == 2) then
  454.       if (value ~= "y" and value ~= "n") then
  455.         onError()
  456.         value = nil
  457.       end
  458.     end
  459.   end
  460.   onSuccess()
  461.   return value
  462. end
  463.  
  464. function configMode()
  465.   local isOk = false
  466.   local widTmp, heiTmp, lenTmp, tmpBlockSlotsToKeep = nil, nil, nil, nil
  467.   local goBackForCobbleTmp, goBackToEmptyTmp, sendOnRednetTmp = nil, nil, nil
  468.   local fillLeftWallTmp, fillRightWallTmp, fillFloorTmp, fillCeilingTmp, fillBackWallTmp = nil, nil, nil, nil, nil
  469.   local digOnlyTmp = nil
  470.   local timeToWait = 0
  471.   local success = function()
  472.     print("Hum... Ok !")
  473.     os.sleep(timeToWait)
  474.   end
  475.   local numberError = function()
  476.     print("Invalid entry : need a strictly positive number.")
  477.     os.sleep(timeToWait)
  478.   end
  479.   local ynError = function()
  480.     print("I told you to ask y or n.")
  481.     os.sleep(timeToWait)
  482.   end
  483.  
  484.   while (not isOk) do
  485.     widTmp = readPrompt("Tunnel width : ", 1, numberError, success, true, true)
  486.     heiTmp = readPrompt("Tunnel height : ", 1, numberError, success, true, true)
  487.     lenTmp = readPrompt("Tunnel length : ", 1, numberError, success, true, true)
  488.     digOnlyTmp = readPrompt("Run in dig only ? (y/n) ", 2, ynError, success, true)
  489.     if (digOnlyTmp == "n") then
  490.       fillLeftWallTmp = readPrompt("Should I fill the left wall ? (y/n) ", 2, ynError, success, true)
  491.       fillRightWallTmp = readPrompt("Should I fill the right wall ? (y/n) ", 2, ynError, success, true)
  492.       fillBackWallTmp = readPrompt("Should I fill the back wall ? (y/n) ", 2, ynError, success, true)
  493.       fillFloorTmp = readPrompt("Should I fill the floor ? (y/n) ", 2, ynError, success, true)
  494.       fillCeilingTmp = readPrompt("Should I fill the ceiling ? (y/n) ", 2, ynError, success, true)
  495.       if (fillLeftWallTmp == "n" and fillRightWallTmp == "n" and fillBackWallTmp == "n" and fillFloorTmp == "n" and fillCeilingTmp == "n") then
  496.         digOnlyTmp = "y"
  497.       end
  498.     end
  499.     if (digOnlyTmp == "n") then
  500.       tmpBlockSlotsToKeep = readPrompt("How many slots do you want me to keep for filling blocks ? ", 1, numberError, success, true, true)
  501.       goBackForCobbleTmp = readPrompt("Should I go back to start when I need filling blocks ? (y/n) ", 2, ynError, success, true)
  502.     end
  503.     goBackToEmptyTmp = readPrompt("Should I empty when I'm full ? (y/n) ", 2, ynError, success, true)
  504.     sendOnRednetTmp = readPrompt("Should I send infos on rednet ? (y/n) ", 2, ynError, success, true)
  505.     shell.run("clear")
  506.     print("Tunnel w = "..widTmp.." h = "..heiTmp.." l = "..lenTmp)
  507.     print("Dig Only : "..digOnlyTmp)
  508.     if (digOnlyTmp == "n") then
  509.       print("Fill left wall : "..fillLeftWallTmp)
  510.       print("Fill right wall : "..fillRightWallTmp)
  511.       print("Fill back wall : "..fillBackWallTmp)
  512.       print("Fill floor wall : "..fillFloorTmp)
  513.       print("Fill ceiling wall : "..fillCeilingTmp)
  514.       print("Blocks to keep : "..tmpBlockSlotsToKeep)
  515.       print("Back when need blocks : "..goBackForCobbleTmp)
  516.     end
  517.     print("Empty when full : "..goBackToEmptyTmp)
  518.     print("Infos on rednet : "..sendOnRednetTmp)
  519.     print("")
  520.     isOk = readPrompt("Is this ok for you ? (y/n) ", 2, ynError, success, false)
  521.     if (isOk == "y") then isOk = true else isOk = false end
  522.   end
  523.   width = widTmp
  524.   height = heiTmp
  525.   length = lenTmp
  526.   blockSlotsToKeep = tmpBlockSlotsToKeep
  527.   if (digOnlyTmp == "y") then digOnly = true else digOnly = false end
  528.  
  529.   if (fillLeftWallTmp == "y") then fillLeftWall = true else fillLeftWall = false end
  530.   if (fillRightWallTmp == "y") then fillRightWall = true else fillRightWall = false end
  531.   if (fillBackWallTmp == "y") then fillBackWall = true else fillBackWall = false end
  532.   if (fillCeilingTmp == "y") then fillCeiling = true else fillCeiling = false end
  533.   if (fillFloorTmp == "y") then fillFloor = true else fillFloor = false end
  534.  
  535.   if (goBackForCobbleTmp == "y") then goBackForCobble = true else goBackForCobble = false end
  536.   if (goBackToEmptyTmp == "y") then goBackForEmpty = true else goBackForEmpty = false end
  537.   if (sendOnRednetTmp == "y") then sendOnRednet = true else sendOnRednet = false end
  538. end
  539.  
  540. function dig(face)
  541.   if (face == nil) then
  542.     while (turtle.detect()) do
  543.       while (not turtle.dig()) do
  544.         turtle.attack()
  545.       end
  546.       os.sleep(0.5)
  547.       infos.blocksDug = infos.blocksDug + 1
  548.     end
  549.   elseif (face == "up") then
  550.     while (turtle.detectUp()) do
  551.       while (not turtle.digUp()) do
  552.         turtle.attackUp()
  553.       end
  554.       os.sleep(0.5)
  555.       infos.blocksDug = infos.blocksDug + 1
  556.     end
  557.   elseif (face == "down") then
  558.     while (not turtle.digDown()) do
  559.       turtle.attackDown()
  560.     end
  561.     infos.blocksDug = infos.blocksDug + 1
  562.   end
  563. end
  564.  
  565. function checkBlock()
  566.   local countBlock = 0
  567.  
  568.   if (digOnly) then
  569.     return
  570.   end
  571.  
  572.   if (turtle.getItemCount(1) < 5) then
  573.     manageInventory()
  574.   else
  575.     return
  576.   end
  577.  
  578.   for i = 1, blockSlotsToKeep do
  579.     turtle.select(i)
  580.     if (turtle.compareTo(1)) then
  581.       countBlock = countBlock + turtle.getItemCount(i)
  582.     end
  583.   end
  584.  
  585.   if (countBlock < 5 and goBackForCobble) then
  586.     tell("Need block !")
  587.     if (moved == 0) then goToPos(-1 * x, -1 * y, -1 * z, -1 * side, "szyx") end
  588.     moved = 1
  589.     os.sleep(10)
  590.     return checkBlock()
  591.   end
  592.   if (moved == 1) then
  593.     tell("Going back to work !")
  594.     goToPos(x, y, z, side, "zyxs")
  595.     moved = 0
  596.   end
  597. end
  598.  
  599. function left()
  600.   turnLeft()
  601.   forward()
  602.   turnRight()
  603. end
  604.  
  605. function forward()
  606.   while (not turtle.forward()) do
  607.     if (turtle.detect()) then
  608.       turtle.dig()
  609.     else
  610.       turtle.attack()
  611.     end
  612.   end
  613.   if (side == 0) then
  614.     x = x + 1
  615.   elseif (side == 1) then
  616.     y = y + 1
  617.   elseif (side == 2) then
  618.     x = x - 1
  619.   elseif (side == 3) then
  620.     y = y - 1
  621.   else
  622.     tell("Unknown side found : "..side)
  623.   end
  624.   p = p + 1
  625. end
  626.  
  627. function back()
  628.   if (turtle.back()) then
  629.     if (side == 0) then
  630.       x = x - 1
  631.     elseif (side == 1) then
  632.       y = y - 1
  633.     elseif (side == 2) then
  634.       x = x + 1
  635.     elseif (side == 3) then
  636.       y = y + 1
  637.     else
  638.       tell("Unknown side found : "..side)
  639.     end
  640.   else
  641.     turtle.turnLeft()
  642.     turtle.turnLeft()
  643.     forward()
  644.     turtle.turnRight()
  645.     turtle.turnRight()
  646.   end
  647. end
  648.  
  649. function up()
  650.   while (not turtle.up()) do
  651.     if (turtle.detectUp()) then
  652.       turtle.digUp()
  653.     else
  654.       turtle.attackUp()
  655.     end
  656.   end
  657.   z = z + 1
  658.   p = p + 1
  659. end
  660.  
  661. function down()
  662.   while (not turtle.down()) do
  663.     if (turtle.detectDown()) then
  664.       turtle.digDown()
  665.     else
  666.       turtle.attackDown()
  667.     end
  668.   end
  669.   z = z - 1
  670. end
  671.  
  672. function turnLeft()
  673.   turtle.turnLeft()
  674.   side = side - 1
  675.   if (side < 0) then
  676.     side = side + 4
  677.   end
  678. end
  679.  
  680. function turnRight()
  681.   turtle.turnRight()
  682.   side = side + 1
  683.   if (side >= 4) then
  684.     side = side - 4
  685.   end
  686. end
  687.  
  688. function right()
  689.   turnRight()
  690.   forward()
  691.   turnLeft()
  692. end
  693.  
  694. function tell(message)
  695.   screenQuery("update", "message", message)
  696.   screenQuery("draw")
  697.   if (sendOnRednet) then
  698.     rednet.broadcast(name.." "..message)
  699.   end
  700. end
  701.  
  702. function goToPos(xTmp, yTmp, zTmp, sideTmp, order)
  703.   local xMove = function()
  704.     while (xTmp ~= 0) do
  705.       if (xTmp > 0) then
  706.         while (not turtle.forward()) do
  707.           turtle.dig()
  708.           turtle.attack()
  709.           os.sleep(0.4)
  710.         end
  711.         xTmp = xTmp - 1
  712.       else
  713.         if (not turtle.back()) then
  714.           turtle.turnLeft()
  715.           turtle.turnLeft()
  716.           while (not turtle.forward()) do
  717.             turtle.dig()
  718.             turtle.attack()
  719.             os.sleep(0.4)
  720.           end
  721.           turtle.turnRight()
  722.           turtle.turnRight()
  723.         end
  724.         xTmp = xTmp + 1
  725.       end
  726.     end
  727.   end
  728.   local yMove = function()
  729.     if (yTmp > 0) then
  730.       turtle.turnRight()
  731.       while (yTmp > 0) do
  732.         while (not turtle.forward()) do
  733.           turtle.dig()
  734.           turtle.attack()
  735.           os.sleep(0.4)
  736.         end
  737.         yTmp = yTmp - 1
  738.       end
  739.       turtle.turnLeft()
  740.     elseif (yTmp < 0) then
  741.       turtle.turnLeft()
  742.       while (yTmp < 0) do
  743.         while (not turtle.forward()) do
  744.           turtle.dig()
  745.           turtle.attack()
  746.           os.sleep(0.4)
  747.         end
  748.         yTmp = yTmp + 1
  749.       end
  750.       turtle.turnRight()
  751.     end
  752.   end
  753.   local zMove = function()
  754.     while (zTmp ~= 0) do
  755.       if (zTmp < 0) then
  756.         while (not turtle.down()) do
  757.           turtle.attackDown()
  758.           turtle.digDown()
  759.           os.sleep(0.4)
  760.         end
  761.         zTmp = zTmp + 1
  762.       else
  763.         while (not turtle.up()) do
  764.           turtle.attackUp()
  765.           turtle.digUp()
  766.           os.sleep(0.4)
  767.         end
  768.         zTmp = zTmp - 1
  769.       end
  770.     end
  771.   end
  772.   local sMove = function()
  773.     while (sideTmp ~= 0) do
  774.       if (sideTmp > 0) then
  775.         turtle.turnRight()
  776.         sideTmp = sideTmp - 1
  777.       else
  778.         turtle.turnLeft()
  779.         sideTmp = sideTmp + 1
  780.       end
  781.     end
  782.   end
  783.  
  784.   for a = 1, 4 do
  785.     if (order:sub(a, a) == "x") then
  786.       xMove()
  787.     elseif (order:sub(a, a) == "y") then
  788.       yMove()
  789.     elseif (order:sub(a, a) == "z") then
  790.       zMove()
  791.     elseif (order:sub(a, a) == "s") then
  792.       sMove()
  793.     end
  794.   end
  795. end
  796.  
  797. -- Point de départ du programme --
  798. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement