Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local component = require("component")
- local robot = require("robot")
- local event = require("event")
- local computer = require("computer")
- local isRunning = true
- local isHarvestRunning = false
- local harvestTimer = nil
- local waitTimeMinutes = 1
- local minChargePercent = 98
- function strafeRow()
- for i=0,6,1 do
- robot.use()
- robot.forward()
- end
- end
- function strafeField()
- strafeRow()
- robot.turnLeft()
- robot.forward()
- robot.turnLeft()
- strafeRow()
- robot.turnRight()
- robot.forward()
- robot.turnRight()
- strafeRow()
- end
- function harvestField()
- strafeField()
- robot.turnAround()
- strafeField()
- end
- function drainToChest()
- for i=1,robot.inventorySize(),1 do
- robot.select(i)
- if (robot.count() > 0) then
- robot.dropDown()
- end
- end
- robot.select(1)
- end
- function needsPower()
- return (computer.energy()/computer.maxEnergy()*100 < minChargePercent)
- end
- function BeginHarvest()
- if (isHarvestRunning) then
- return
- end
- isHarvestRunning = true
- print("Collecting crops")
- harvestField()
- robot.turnAround()
- print("Draining to chest")
- drainToChest()
- if (needsPower()) then
- print("Needs Charging")
- robot.turnLeft()
- robot.forward()
- repeat
- print("Charging...")
- os.sleep(1)
- until (computer.energy()/computer.maxEnergy()*100 >= 99)
- robot.turnAround()
- robot.forward()
- robot.turnLeft()
- print("Chargine finished")
- end
- isHarvestRunning = false
- print("Waiting " .. waitTimeMinutes .. " minutes")
- print("Press X to stop program")
- end
- --BeginHarvest()
- function ListenTest()
- print("Starting Harvest")
- print("Waiting " .. waitTimeMinutes .. " minutes")
- print("Press X to stop program")
- harvestTimer = event.timer(waitTimeMinutes * 60, BeginHarvest, math.huge)
- while isRunning do
- local test, _, keyval = event.pull(math.huge, "key_up")
- if (test ~= nil and keyval == 120) then
- event.cancel(harvestTimer)
- isRunning = false
- end
- end
- end
- ListenTest()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement