Kaerius

Obsidian

Jul 12th, 2013
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.37 KB | None | 0 0
  1. local pArgs = { ... }
  2. local i = 0
  3. local size = 0
  4. function error1()
  5.  print("Usage: obsidian <path> <swing>")
  6.  print("path, 0 - endless movement")
  7.  print("swing, left = l or right = r")
  8. end
  9. if #pArgs < 2 then
  10.  error1()
  11.  return
  12. end
  13. local statis = {0,0,0,0}
  14. local coor = {["x"] = 0, ["y"] = 0, ["c"] = 5} --X, Y, Course
  15. local size = tonumber( pArgs[1] )
  16. if pArgs[2] == "l" then
  17.  i = 1
  18. else
  19.  if pArgs[2] == "r" then
  20.   i = 2
  21.  else
  22.   error1()
  23.   return
  24.  end
  25. end
  26. function coordina(xi)
  27.  if coor.c == 5 or coor.c == 9 or coor.c == 1 then
  28.   coor.c = 5
  29.  end
  30.  if xi then
  31.   if coor.c == 6 or coor.c == 4 then
  32.    coor.y = coor.y + 1
  33.    
  34.   end
  35.   if coor.c == 8 or coor.c == 2 then
  36.    coor.y = coor.y - 1
  37.   end
  38.   if coor.c == 5 or coor.c == 9 or coor.c == 1 then
  39.    coor.x = coor.x + 1
  40.    coor.c = 5
  41.   end
  42.   if coor.c == 7 or coor.c == 3 then
  43.    coor.x = coor.x - 1
  44.   end
  45.  end
  46. end
  47. function turnLeft()
  48.  if turtle.turnLeft() then
  49.   coor.c = coor.c - 1
  50.  end
  51.  coordina()
  52. end
  53. function turnRight()
  54.  if turtle.turnRight() then
  55.   coor.c = coor.c + 1
  56.  end
  57.  coordina()
  58. end
  59. function swing()
  60.  if i == 1 then
  61.   turnLeft()
  62.   fo()
  63.   turnLeft()
  64.   i = i + 1
  65.   statis[3] = statis[3] + 1
  66.  else
  67.   if i == 2 then
  68.    turnRight()
  69.    fo()
  70.    turnRight()
  71.    i = i - 1
  72.    statis[4] = statis[4] + 1
  73.   else
  74.   end
  75.  end
  76. end
  77. function ref()
  78.  while true do
  79.   if turtle.getFuelLevel() > 0 then
  80.    return true
  81.   else
  82.    shell.run('clear')
  83.    monitor()
  84.    print("Add Fuel")
  85.    sleep(1)
  86.    shell.run('refuel')
  87.   end
  88.  end
  89. end
  90. function fo()
  91.  ref()
  92.  if turtle.forward() then
  93.   statis[2] = statis[2] + 1
  94.   coordina(true)
  95.   return true
  96.  else
  97.   return false
  98.  end
  99. end
  100. function last()
  101. if statis[3] + statis[4] > coor.y then
  102.   print( "End of the room: ", (statis[3] + statis[4])," > ", coor.y)
  103.   return true
  104.  end
  105. end
  106. function monitor()
  107.  shell.run('clear')
  108.  print()
  109.  print("Fuel level is ", turtle.getFuelLevel())
  110.  print("Blocks excavated ", statis[1])
  111.  print("Distance travel ", statis[2])
  112.  print("How many turns")
  113.  print("left: ", statis[3], " right: ", statis[4])
  114.  print("X: ", coor.x, " Y: ", coor.y, " Course: ", coor.c)
  115.  print()
  116. end
  117. while true do
  118.  if size ~= 0 then
  119.   if size > statis[2] then
  120.    else break
  121.   end
  122.  end
  123.  if last() then
  124.   break
  125.  end
  126.  if turtle.digDown() then
  127.   statis[1] = statis[1] + 1
  128.  end
  129.  if not fo() then
  130.   swing()
  131.  end
  132.  monitor()
  133. end
Advertisement
Add Comment
Please, Sign In to add comment