Advertisement
Guest User

planter

a guest
Jul 18th, 2020
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.56 KB | None | 0 0
  1. local ms = require("movescript")
  2. local robot = require("robot")
  3. local component = require("component")
  4. local ic = component.inventory_controller
  5.  
  6. local function equipItemOrWait(name)
  7.   repeat
  8.     local success = ms.selectItem(name)
  9.     if not success then
  10.       print("Please add more " .. name .. ", then press enter.")
  11.       io.read()
  12.     end
  13.   until success
  14.   ic.equip()
  15. end
  16.  
  17. local function goToNextSpot()
  18.   equipItemOrWait("pickaxe")
  19.   while robot.detect() do
  20.     ms.exec("d_U")
  21.   end
  22.   ms.exec("F")
  23.   while not robot.detectDown() do
  24.     ms.exec("d_D")
  25.   end
  26.   ms.exec("d_U")
  27. end
  28.  
  29. local function plantSpot(cropName)
  30.   repeat
  31.     equipItemOrWait("hoe")
  32.     robot.useDown()
  33.     equipItemOrWait(cropName)
  34.     local success = robot.useDown()
  35.   until success
  36. end
  37.  
  38. local function plantArea(length, width, cropName)
  39.   goToNextSpot()
  40.   plantSpot(cropName)
  41.   ms.exec("R")
  42.   for row = 1, length do
  43.     for col = 1, width - 1 do
  44.       goToNextSpot()
  45.       plantSpot(cropName)
  46.     end
  47.     if row % 2 == 1 then
  48.       ms.exec("L")
  49.     else
  50.       ms.exec("R")
  51.     end
  52.     if row ~= length then
  53.       goToNextSpot()
  54.       plantSpot(cropName)
  55.     end
  56.     if row % 2 == 1 then
  57.       ms.exec("L")
  58.     else
  59.       ms.exec("R")
  60.     end
  61.     print("Completed row " .. row .. " of " .. length)
  62.   end
  63. end
  64.  
  65.  
  66. local args = {...}
  67.  
  68. local length = tonumber(args[1])
  69. local width = tonumber(args[2])
  70. local cropName = args[3]
  71. if not length or not width or not cropName then
  72.   error("Invalid args.")
  73. end
  74. print("Planting an area " .. length .. " by " .. width .. " with " .. cropName .. ".")
  75. plantArea(length, width, cropName)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement