Facebook
From as, 1 Month ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 159
  1. rednet.open("right")
  2. connected = 0
  3. oid = 0
  4. x = 0
  5. y = 0
  6. z = 0
  7. rotation = 0
  8.  
  9. function Forward()
  10.   while turtle.detect() do
  11.     turtle.dig()
  12.   end
  13.   turtle.forward()
  14.   while turtle.detectUp() do
  15.     turtle.digUp()
  16.   end
  17.   while turtle.detectDown() do
  18.     turtle.digDown()
  19.   end
  20.   if rotation == 0 then
  21.     z = z - 1
  22.   elseif rotation == 1 then
  23.     x = x - 1
  24.   elseif rotation == 2 then
  25.     z = z + 1
  26.   elseif rotation == 3 then
  27.     x = x + 1
  28.   end
  29. end
  30.  
  31. function Left()
  32.   turtle.turnLeft()
  33.   if rotation < 3 then
  34.      rotati + 1
  35.   else
  36.      rotati
  37.   end
  38. end
  39.  
  40. function Right()
  41.   turtle.turnRight()
  42.   if rotation > 0 then
  43.     rotation = rotation - 1
  44.   else
  45.     rotation = 3
  46.   end
  47. end
  48.  
  49. function Backwards()
  50.   turtle.back()
  51.   if rotation == 0 then
  52.     z = z + 1
  53.   elseif rotation == 1 then
  54.     x = x + 1
  55.   elseif rotation == 2 then
  56.     z = z - 1
  57.   elseif rotation == 3 then
  58.     x = x - 1
  59.   end
  60. end
  61.  
  62. function Up()
  63. end
  64.  
  65. function Down()
  66. end
  67.  
  68. function StartMine()
  69.   distance = 0
  70.   while true do
  71.     distance = distance + 1
  72.     if distance < 25 then
  73.       Forward()
  74.      elseif rotati 0 then
  75.       Left()
  76.       Forward()
  77.       Left()
  78.       distance = 0
  79.      elseif rotati 2 then
  80.       Right()
  81.       Forward()
  82.       Right()
  83.       distance = 0
  84.     end
  85.     id, msg = rednet.receive(1)
  86.     if id == oid and msg == "StopMine" then
  87.       break
  88.     end
  89.   end
  90. end
  91.  
  92. function Return()
  93.   while true do
  94.     if rotation > 0 then
  95.       Right()
  96.     else
  97.       if z > 0 then
  98.         Forward()
  99.       elseif z < 0 then
  100.         Left()
  101.         Left()
  102.         while z < 0 do
  103.           Forward()
  104.         end
  105.       elseif x > 0 then
  106.         while rotation ~= 1 do
  107.           Left()
  108.         end
  109.         Forward()
  110.       elseif x < 0 then
  111.         while rotation ~= 3 do
  112.           Left()
  113.         end
  114.         Forward()
  115.         break
  116.       end
  117.     end
  118.   end
  119. end
  120.  
  121. while true do
  122.    if c 0 then
  123.     id, msg = rednet.receive()
  124.     print("got msg: " .. msg)
  125.     if msg == "Connect" then
  126.       rednet.send(id, "kt")
  127.       print("sent msg: kt")
  128.       oid = id
  129.       id, msg = rednet.receive()
  130.       print("got msg: " .. msg)
  131.       if id == oid then
  132.          c
  133.       end
  134.     end
  135.    elseif c 1 then
  136.     id, msg = rednet.receive()
  137.     print("got msg: " .. msg)
  138.     if msg == "Mine" and id == oid then
  139.       StartMine()
  140.     elseif msg == "Return" and id == oid then
  141.       Return()
  142.     end
  143.   end
  144. end
  145.  
  146.  
  147.