Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- do_veggies (part of FarmerTurt)
- -----------------------------------------------------------------------
- --[[
- ("This program is currently intended for use with melon and pumpkin farms")
- ("The turtle must be placed with 1 empty block between the first possible farm item and the turtle")
- ("There must be a chest to the right of where the turtle is placed before starting the program to ensure correct dropoff")
- ("This program assumes a 4 wide system for Melons and Pumpkins, the length is variable:")
- ("D = Dirt(or other): W = Water: S = Seed: C = Chest: T = Turtle: M = Melon or Pumpkin Crop")
- (" W DDDDDDDDDDDD ")
- (" I DSSSSSSSSSSDC ")
- (" D DMMMMMMMMMM T ")
- (" T DMMMMMMMMMM ")
- (" H DSSSSSSSSSSD ")
- (" DWWWWWWWWWWD ")
- (" LENGTH ")
- --]]
- term.clear()
- term.setCursorPos(1, 1)
- minerID = os.getComputerID()
- turtleName = nil
- consoleID = 0
- version = "1.0"
- function getConsoleID()
- local fname = "ConsoleID"
- if fs.exists(fname) then
- file = fs.open(fname, "r")
- consoleID = tonumber(file.readAll())
- file.close()
- print("Monitor Console ID: "..consoleID)
- else
- updateStatus("Waiting for Console ID...",true)
- term.write("Monitor Console ID: ")
- consoleID = io.read()
- file = fs.open(fname, "w")
- file.write(consoleID)
- file.close()
- consoleID = tonumber(consoleID)
- end
- end
- function updateStatus(msg, silent)
- if not rednet.isOpen("right") then rednet.open("right") end
- if rednet.isOpen("right") then
- if turtleName == nil then return end
- networkmsg = "MM:"..turtleName..": "..msg
- if consoleID == 0 then
- rednet.broadcast(networkmsg)
- else
- rednet.send(consoleID,networkmsg)
- end
- end
- if not silent then print(msg) end
- end
- function getTurtleName()
- local fname = "TurtleName"
- if fs.exists(fname) then
- file = fs.open(fname, "r")
- turtleName = file.readAll()
- file.close()
- else
- term.write("Turtle Name: ")
- turtleName = io.read()
- file = fs.open(fname, "w")
- file.write(turtleName)
- file.close()
- end
- end
- -- Main Program
- updateStatus("Starting")
- term.clear()
- term.setCursorPos(1,1)
- getTurtleName()
- getConsoleID()
- function update()
- end
- function questions()
- --Questions that are asked in order to get the variables needed to function customizeably
- print("How many blocks long to farm?")
- blocksDown = io.read()
- print("How many times to run?")
- qtyRepeat = io.read()
- if tonumber(qtyRepeat) > 1 then
- print("How long to wait between farmings?")
- farmWait = io.read()
- else
- farmWait = 0
- end
- print("How many farms wide?")
- numFarms = io.read()
- declarations()
- end
- function declarations()
- --Sets all variable needed to restart the program from scratch
- i = 0
- currentQty = 0
- startBlock = 0
- currentFarm = 1
- prime()
- end
- function prime()
- --Calls the fueling fuction and gets the turtle to the correct spot to start farming
- fuelItUp()
- turtle.forward()
- farmdown()
- end
- function fuelItUp()
- updateStatus("...Working")
- --Finds out if the turtle needs to refuel and if it has fuel to run
- needsFuel = turtle.getFuelLevel()
- minimumFuelLevel = 10
- hasFuel = turtle.getItemCount(16)
- useFuel = turtle.refuel()
- if needsFuel == "unlimited" then
- else
- if tonumber(needsFuel) < tonumber(minimumFuelLevel) then
- if hasFuel > 0 then
- turtle.select(16)
- turtle.refuel(1)
- turtle.select(1)
- else
- print("Please insert fuel into slot 16")
- updateStatus("...Need Fuel")
- repeat os.sleep(1)
- until tonumber(turtle.getItemCount(16)) > 0
- fuelItUp()
- end
- end
- end
- end
- function farmdown()
- turtle.select(1)
- --Moves the turtle down the set number of blocks checking for items infront of him and harvesting if there is
- while i ~= tonumber(blocksDown) do
- fuelItUp()
- detected = turtle.detect()
- if detected == true then
- turtle.dig()
- turtle.suck()
- turtle.forward()
- i = i + 1
- else
- turtle.forward()
- i = i + 1
- end
- detected = false
- end
- turn()
- end
- function turn()
- --Turns the robot to the left once the number of blocks down has been reached and if there is a block when he turns, he harvests it
- turtle.turnLeft()
- detected = turtle.detect()
- if detected == true then
- turtle.dig()
- turtle.suck()
- end
- detected = false
- turtle.forward()
- turtle.turnLeft()
- farmback()
- end
- function farmback()
- --Same as the farmDown function but in reverse
- while i ~= startBlock do
- fuelItUp()
- detected = turtle.detect()
- if detected == true then
- turtle.dig()
- turtle.suck()
- turtle.forward()
- i = i - 1
- else
- turtle.forward()
- i = i - 1
- end
- detected = false
- end
- movefarms()
- end
- function movefarms()
- farmMessage = "Farm " .. currentFarm .. " of " .. numFarms .. " completed!"
- print(farmMessage)
- if tonumber(currentFarm) ~= tonumber(numFarms) then
- turtle.forward()
- turtle.turnRight()
- turtle.forward()
- turtle.forward()
- turtle.forward()
- turtle.forward()
- turtle.turnRight()
- currentFarm = currentFarm + 1
- prime()
- else
- dropoff()
- end
- end
- function dropoff()
- updateStatus("Finished")
- --Moves the robot from the ending position to the chest for item dropoff and counts how many items collected in total, does not deposit the fuel in slot 16
- turtle.forward()
- turtle.turnLeft()
- turtle.forward()
- while tonumber(currentFarm) ~= 1 do
- fuelItUp()
- turtle.forward()
- turtle.forward()
- turtle.forward()
- turtle.forward()
- turtle.forward()
- currentFarm = currentFarm - 1
- end
- s = 1
- total = 0
- while s < 16 do
- items = turtle.getItemCount(s)
- total = items + total
- if items > 0 then
- turtle.select(s)
- turtle.drop()
- end
- s = s + 1
- end
- turtle.turnLeft()
- print("Total Items Deposited:")
- print(total)
- updateStatus("Total Items Deposited " ..total)
- if tonumber(qtyRepeat) < 1 then
- qtyRepeat = 1
- end
- currentQty = currentQty + 1
- completeMessage = "Round " .. currentQty .. " of " .. qtyRepeat .. " completed!"
- print(completeMessage)
- --This repeats the program while the current turn is not equal to the repeat quantity specified
- while tonumber(currentQty) ~= tonumber(qtyRepeat) do
- os.sleep(tonumber(farmWait))
- prime()
- end
- end
- questions()
- print("Press Enter to Continue")
- io.read()
- os.reboot()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement