SHARE
TWEET

Untitled

a guest Jul 16th, 2019 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --1:z+  2:x-   3:z-  4:x+
  2. local args = {...}
  3. local wX=-861
  4. local wY=68
  5. local wZ=-566
  6.  
  7. --Functii
  8. function turn(poz)
  9.     print("Turn " .. poz)
  10.     local run2=1
  11.     if poz==heading then
  12.         return
  13.     end
  14.     if poz==heading-1 then
  15.         turtle.turnLeft()
  16.         run2=0
  17.     end
  18.     if poz==4 then
  19.         if heading==1 then
  20.             turtle.turnLeft()
  21.             run2=0
  22.         end
  23.     end
  24.     if poz==1 then
  25.         if heading==4 then
  26.             turtle.turnRight()
  27.             run2=0
  28.         end
  29.     end
  30.     if run2==1 then
  31.         if poz==heading+1 then
  32.             turtle.turnRight()
  33.         else
  34.             turtle.turnRight()
  35.             turtle.turnRight()
  36.         end
  37.     end
  38.  
  39.     heading = poz
  40.     save_coord()
  41. end
  42. function mergi_coord(X_dorit, Y_dorit, Z_dorit, prioritate_Y)
  43.     if prioritate_Y==1 then
  44.         mergi_y(Y_dorit)
  45.     end
  46.     mergi_x(X_dorit)
  47.     mergi_z(Z_dorit)
  48.     if prioritate_Y==0 then
  49.         mergi_y(Y_dorit)
  50.     end
  51. end
  52. function mergi_x(X_dorit)
  53.     local add_val=0
  54.     if my_X>X_dorit then
  55.         turn(2)
  56.         add_val=-1
  57.     elseif my_X<X_dorit then
  58.         turn(4)
  59.         add_val=1
  60.     end
  61.     local de_mers=math.abs(my_X-X_dorit)
  62.     print("Merg pe X "..de_mers)
  63.     for i=1,de_mers do
  64.         turtle.dig()
  65.         turtle.forward()
  66.         my_X=my_X+add_val
  67.         save_coord()
  68.     end
  69. end
  70. function mergi_z(Z_dorit)
  71.     local add_val=0
  72.     if my_Z>Z_dorit then
  73.         turn(3)
  74.         add_val=-1
  75.     elseif my_Z<Z_dorit then
  76.         turn(1)
  77.         add_val=1
  78.     end
  79.     local de_mers=math.abs(my_Z-Z_dorit)
  80.     print("Merg pe Z "..de_mers)
  81.     for i=1,de_mers do
  82.         turtle.dig()
  83.         turtle.forward()
  84.         my_Z=my_Z+add_val
  85.         save_coord()
  86.     end
  87. end
  88. function mergi_y(Y_dorit)
  89.     local de_mers=math.abs(my_Y-Y_dorit)
  90.     print("Merg pe Y "..de_mers)
  91.     if my_Y>Y_dorit then
  92.         for i=1,de_mers do
  93.             turtle.digDown()
  94.             turtle.down()
  95.             my_Y=my_Y-1
  96.             save_coord()
  97.         end
  98.     elseif my_Y<Y_dorit then
  99.             for i=1,de_mers do
  100.             turtle.digUp()
  101.             turtle.up()
  102.             my_Y=my_Y+1
  103.             save_coord()
  104.         end
  105.     end
  106. end
  107. function load_coord()
  108.     --load home
  109.     local home_file = fs.open("home.lua", "r")
  110.     home_X=tonumber(home_file.readLine())
  111.     home_Y=tonumber(home_file.readLine())
  112.     home_Z=tonumber(home_file.readLine())
  113.     home_file.close()
  114.     --load my_coord
  115.     local my_file = fs.open("my.lua", "r")
  116.     my_X=tonumber(my_file.readLine())
  117.     my_Y=tonumber(my_file.readLine())
  118.     my_Z=tonumber(my_file.readLine())
  119.     heading=tonumber(my_file.readLine())
  120.     my_file.close()
  121.     print(heading)
  122. end
  123. function save_coord()
  124.     local my_file = fs.open("my.lua", "w")
  125.     my_file.write(tostring(my_X))
  126.     my_file.write("\n")
  127.     my_file.write(tostring(my_Y))
  128.     my_file.write("\n")
  129.     my_file.write(tostring(my_Z))
  130.     my_file.write("\n")
  131.     my_file.write(tostring(heading))
  132.     my_file.write("\n")
  133.     my_file.close()
  134. end
  135.  
  136.  
  137. load_coord()
  138. mergi_coord(tonumber(args[1]),tonumber(args[2]),tonumber(args[3]),1)
  139. save_coord()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top