Advertisement
Guest User

hemp

a guest
Aug 30th, 2016
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.65 KB | None | 0 0
  1. local term = require("term")
  2. local robot = require("robot")
  3. local args = {...}
  4. local levelCurrent = 1
  5. platforms = args[1]
  6. levels = args[2]
  7. if platforms==nil or levels== nil then
  8.   print("ERROR, MISSING PLATFORMS OR HEIGHT VARS")
  9.   os.exit()
  10. end
  11. function levelUp()
  12.   if select(2,robot.detectUp()) == "solid"  then
  13.     print("MAXIMUM HEIGHT REACHED, ABORTING")
  14.   else
  15.     u(4)
  16.     levelCurrent = levelCurrent + 1
  17.     print("Current level is: " .. levelCurrent)
  18.   end
  19. end
  20. function levelDown()
  21.   if select(2,robot.detectDown()) == "solid"  then
  22.     print("MINIMUM HEIGHT REACHED, ABORTING")
  23.   else
  24.     d(4)
  25.     levelCurrent = levelCurrent - 1
  26.     print("Current level is: " .. levelCurrent)
  27.   end
  28. end
  29. function u(x)
  30.   for i=tonumber(x),1,-1 do
  31.     repeat
  32.       robot.swingUp()
  33.     until(robot.up())
  34.   end
  35. end
  36. function d(x)
  37.   for i=tonumber(x),1,-1 do
  38.     repeat
  39.       robot.swingDown()
  40.     until(robot.down())
  41.   end
  42. end
  43. function f(x)
  44.   for i=tonumber(x),1,-1 do
  45.     repeat
  46.         robot.swing()
  47.     until(robot.forward())
  48.   end
  49. end
  50. function b(x)
  51.   for i=tonumber(x),1,-1 do
  52.     local count = -1
  53.     repeat
  54.       count = count + 1
  55.       if count>0 then
  56.         l(2)
  57.         repeat
  58.           robot.swing()
  59.         until(not robot.detect())
  60.         r(2)
  61.       end
  62.     until(robot.back())
  63.   end
  64. end
  65. function r(x)
  66.   for i=tonumber(x),1,-1 do
  67.     robot.turnRight()
  68.   end
  69. end
  70. function l(x)
  71.   for i=tonumber(x),1,-1 do
  72.     robot.turnLeft()
  73.   end
  74. end
  75.  
  76. function clearPlatform()
  77.   r(1)
  78.   f(2)
  79.   l(1)
  80.   f(5)
  81.   l(1)
  82.   f(4)
  83.   l(1)
  84.   f(4)
  85.   l(1)
  86.   f(3)
  87.   l(1)
  88.   f(3)
  89.   l(1)
  90.   f(2)
  91.   l(1)
  92.   f(2)  
  93.   l(1)
  94.   f(1)
  95. end
  96. function clearLevel()
  97.   local effective = 0
  98.   for i=tonumber(platforms),1,-1 do
  99.     effective = effective + 1
  100.     f(2)
  101.     clearPlatform()
  102.     l(1)
  103.     if(i==1) then
  104.       f(3)
  105.       if(select(2,robot.detect())=="solid") then
  106.         print("LAST PLATFORM, ABORTING NEXT ITERATIONS")
  107.         break
  108.       end
  109.     else
  110.       f(4)
  111.     end
  112.   end
  113.   r(2)
  114.   f(((effective*5) + (effective*3))-1)
  115.   r(2)
  116. end
  117. function dropStuff()
  118.   local perc = 0
  119.   local tot = 100/robot.inventorySize()
  120.   for i=robot.inventorySize(),1,-1 do
  121.     robot.select(i)
  122.     robot.dropDown()
  123.     perc = perc + tot
  124.     term.clearLine()
  125.     io.write("DROPPING ITEMS: " .. math.ceil(perc) .. "%")  
  126.   end
  127.   print(" ")
  128. end
  129.  
  130.  
  131. while true do
  132.   for i=1,tonumber(levels),1 do
  133.     print("Now going for level: " .. i  )
  134.     print("Current level is: " .. levelCurrent)
  135.     if(not(levelCurrent == i)) then
  136.      
  137.       repeat
  138.         levelUp()
  139.       until(tonumber(levelCurrent) == i)
  140.     end
  141.     clearLevel()
  142.     if(not(levelCurrent == 1)) then
  143.       repeat
  144.         levelDown()
  145.       until(levelCurrent==1)
  146.     end
  147.     dropStuff()  
  148.   end
  149.   os.sleep(300)
  150. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement