Advertisement
Guest User

startup

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