Advertisement
artem211

q1.1

Jan 1st, 2013
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.35 KB | None | 0 0
  1. t=turtle
  2.  
  3. r=1
  4.  
  5. x=0
  6.  
  7. y=0
  8.  
  9. z=0
  10.  
  11. d=0
  12.  
  13.  
  14.  
  15. function calc()
  16.  
  17.   zm=z
  18.  
  19.   if z<0 then zm = -z end
  20.  
  21.   clcrd=zm+x+y
  22.  
  23.   clc=(t.getItemCount(1)*80)
  24.  
  25.   if (clc-clcrd)<100 then target(0,0,0)
  26.  
  27.     while (clc-t.getItemCount(1)*100)<100 do
  28.  
  29.       print('Food plz...')
  30.  
  31.       sleep(4)
  32.  
  33.     end
  34.  
  35.    
  36.  
  37.   end
  38.  
  39. end  
  40.  
  41.  
  42.  
  43. function rfl(s)
  44.  
  45.   if t.getFuelLevel() <= 10 then
  46.  
  47.     t.select(s)
  48.  
  49.     t.refuel(1)
  50.  
  51.   end
  52.  
  53.   calc()
  54.  
  55. end
  56.  
  57.  
  58.  
  59. function trn(rtn)
  60.  
  61.   while not(r==rtn) do
  62.  
  63.     if r==1 then r=4 t.turnLeft() else
  64.  
  65.     t.turnLeft() r=r-1 end
  66.  
  67.   end
  68.  
  69. end
  70.  
  71.  
  72.  
  73. function mv2(zk)
  74.  
  75. t=turtle
  76.  
  77.   if zk>z then
  78.  
  79.     while not(z==zk) do
  80.  
  81.       rfl(1)
  82.  
  83.       while t.detectUp() do
  84.  
  85.         t.digUp()
  86.  
  87.         sleep(0.1)
  88.  
  89.       end
  90.  
  91.       t.up()
  92.  
  93.       z=z+1
  94.  
  95.     end
  96.  
  97.   else
  98.  
  99.     if zk<z then
  100.  
  101.       while not(z==zk) do
  102.  
  103.         rfl(1)
  104.  
  105.         while t.detectDown() do
  106.  
  107.           if not(t.digDown()) then
  108.  
  109.             target(0,0,0)
  110.  
  111.             trn(3)
  112.  
  113.             drop(1)
  114.  
  115.             print('BedRock')
  116.  
  117.             exit()
  118.  
  119.           end
  120.  
  121.         end
  122.  
  123.         t.digUp()
  124.  
  125.         t.down()
  126.  
  127.         z=z-1
  128.  
  129.        
  130.  
  131.       end
  132.  
  133.     end
  134.  
  135.   end
  136.  
  137.  
  138.  
  139. end
  140.  
  141.  
  142.  
  143. function drop(tr)
  144.  
  145.     xp = x
  146.  
  147.     yp = y
  148.  
  149.     zp = z
  150.  
  151.     rp = r
  152.  
  153.     if t.getItemCount(12) > 0 then
  154.  
  155.        
  156.  
  157.       target(0,0,0)
  158.  
  159.       trn(3)
  160.  
  161.       for i=2,16 do
  162.  
  163.         t.select(i)
  164.  
  165.         t.drop()
  166.  
  167.       end
  168.  
  169.       t.select(2)
  170.  
  171.       if not(tr==1) then  
  172.  
  173.         target(xp,yp,zp)
  174.  
  175.         trn(rp)
  176.  
  177.       end
  178.  
  179.     end
  180.  
  181.    
  182.  
  183. end
  184.  
  185.  
  186.  
  187. function mv1(n)
  188.  
  189.   for i=1,n do
  190.  
  191.     rfl(1)
  192.  
  193.     while t.detect() do
  194.  
  195.       ktv=0
  196.  
  197.       while not(t.dig()) do
  198.  
  199.         ktv=ktv+1
  200.  
  201.         if ktv==14 then
  202.  
  203.           target(0,0,0)
  204.  
  205.           trn(3)
  206.  
  207.           drop(1)
  208.  
  209.           exit()
  210.  
  211.         end
  212.  
  213.         sleep(0.2)
  214.  
  215.         t.dig()
  216.  
  217.       end
  218.  
  219.       ktv=0
  220.  
  221.     end
  222.  
  223.    
  224.  
  225.     while t.detectUp() do
  226.  
  227.       t.digUp()
  228.  
  229.        
  230.  
  231.       sleep(0.2)
  232.  
  233.     end
  234.  
  235.     while t.detectDown() do
  236.  
  237.       t.digDown()
  238.  
  239.        
  240.  
  241.       sleep(0.2)
  242.  
  243.     end
  244.  
  245.     kl=0
  246.  
  247.     while not(t.forward()) do
  248.  
  249.       kl=kl+1
  250.  
  251.       t.dig()
  252.  
  253.       if kl==14 then
  254.  
  255.         target(0,0,0)  
  256.  
  257.         trn(3)
  258.  
  259.         for i=2,16 do
  260.  
  261.           t.select(i)
  262.  
  263.           t.drop()
  264.  
  265.         end
  266.  
  267.         t.select(2)
  268.  
  269.         exit()
  270.  
  271.       end
  272.  
  273.     end
  274.  
  275.     kl=0          
  276.  
  277.     crd(r)
  278.  
  279.   end
  280.  
  281. end
  282.  
  283.  
  284.  
  285. function crd(direct)
  286.  
  287.   if direct == 1 then x=x+1 else
  288.  
  289.   if direct == 2 then y=y+1 else
  290.  
  291.   if direct == 3 then x=x-1 else
  292.  
  293.   if direct == 4 then y=y-1 end end end end
  294.  
  295. end
  296.  
  297.  
  298.  
  299.  
  300.  
  301. function target(x1, y1, z1)
  302.  
  303.  
  304.  
  305.   mv2(z1)
  306.  
  307.  
  308.  
  309.   if x1>x then trn(1) mv1(x1-x) else
  310.  
  311.     if x1<x then trn(3) mv1(x-x1)
  312.  
  313.     end
  314.  
  315.   end
  316.  
  317.   if y1>y then trn(2) mv1(y1-y) else
  318.  
  319.     if y1<y then trn(4) mv1(y-y1)
  320.  
  321.     end
  322.  
  323.   end
  324.  
  325. end
  326.  
  327.  
  328.  
  329.  
  330.  
  331. print('Diametr?')
  332.  
  333. h=-2
  334.  
  335. d=tonumber(read())-1
  336.  
  337. print('Now height coord?')
  338.  
  339. min=tonumber(read())-2
  340.  
  341. mv2(h)
  342.  
  343.  
  344.  
  345. for i=1,min do
  346.  
  347.   drop()
  348.  
  349.   for i=1,d do
  350.  
  351.     drop()
  352.  
  353.     if x==0 then
  354.  
  355.       target(d,i,h)
  356.  
  357.       else
  358.  
  359.       target(0,i,h)
  360.  
  361.     end
  362.  
  363.   end
  364.  
  365.  
  366.  
  367.   if x==0 then
  368.  
  369.     target(d,d,h)
  370.  
  371.     else
  372.  
  373.     target(0,d,h)
  374.  
  375.   end
  376.  
  377.   h=h-3
  378.  
  379.   target(0,0,h)
  380.  
  381. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement