Post by nefariis on Mar 15, 2021 0:46:32 GMT
My goals for this script -
1. Account for fertilizer and seed planting failures
2. Be able to choose a range of seeds instead of only being able to plant a single type
3. And lastly, be able to select any size of field in which to garden.
The setup of the script comes down to -
gardeningMacroID is the place where you set the Gardening Skill - in this case it is located in the 1st Macro location
seedID numbers correspond to the location in the seed menu that the seed appears, for example, cotton is the "25" button in the menu.
if you want to just plant cotton, then
if you would like to plant all your common seeds then -
if all you wanted to plant were rare seeds then you would use -
or you could do any range between 25 (the lowest) and 52 (the highest)
lastly you need to select the Field in which you would like to garden -
you will be prompted for the upper left hand bounds of the field, followed by the lower right hand bounds of the field - the script will then fill in the rows and columns based on those bounds.
1. Account for fertilizer and seed planting failures
2. Be able to choose a range of seeds instead of only being able to plant a single type
3. And lastly, be able to select any size of field in which to garden.
The setup of the script comes down to -
local gardeningMacroID = 0
local seedIDNumberLow, seedIDNumberHigh = 25, 44
gardeningMacroID is the place where you set the Gardening Skill - in this case it is located in the 1st Macro location
seedID numbers correspond to the location in the seed menu that the seed appears, for example, cotton is the "25" button in the menu.
if you want to just plant cotton, then
local seedIDNumberLow, seedIDNumberHigh = 25, 25
if you would like to plant all your common seeds then -
local seedIDNumberLow, seedIDNumberHigh = 25, 44
if all you wanted to plant were rare seeds then you would use -
local seedIDNumberLow, seedIDNumberHigh = 45, 52
or you could do any range between 25 (the lowest) and 52 (the highest)
local seedIDNumberLow, seedIDNumberHigh = 25, 52
lastly you need to select the Field in which you would like to garden -
you will be prompted for the upper left hand bounds of the field, followed by the lower right hand bounds of the field - the script will then fill in the rows and columns based on those bounds.
local gardeningMacroID = 0
local seedIDNumberLow, seedIDNumberHigh = 25, 44
local lowestx, highestx, lowestz, highestz
local pileID
-- Function to get the bounds of where to plant
function getBounds()
print("Please define top left gardening location...")
sleep(5000)
ulx, ulz = CLICKWORLDX, CLICKWORLDZ
print(string.format(" - Upper Bounds x: %s, z: %s", ulx, ulz))
print("Please define lower right gardening location...")
sleep(5000)
lrx, lrz = CLICKWORLDX, CLICKWORLDZ
print(string.format(" - Lower Bounds x: %s, z: %s", lrx, lrz))
lowestx, highestx = math.min(ulx, lrx), math.max(ulx, lrx)
lowestz, highestz = math.min(ulz, lrz), math.max(ulz, lrz)
end
-- A custom journal scanner that looks for messages
function JournalScanner(startT, endT, search)
for i = startT, endT, .5 do
ScanJournal(i)
for str in search do
if string.match(SCANJOURNALMESSAGE, str) then
return true
end
end
end
return false
end
-- Starts the planting process at location(x, y)
function startPlantingAt(x, z)
Move(x + 1, CHARPOSY, z)
while CHARPOSX != x + 1 do
sleep(500)
end
Macro(gardeningMacroID)
TargetLoc(x, CHARPOSY, z)
sleep(2000)
return cultivateSoil()
end
-- Cultivate our newly dug hole
function cultivateSoil()
FindItem("messy soil pile")
if not FINDITEM then
return "Could not find hole"
end
pileID = FINDITEM[1].ID
ContextMenu(pileID, "Cultivate Soil")
repeat
sleep(1000)
FindItem("tilled soil")
until FINDITEM
sleep(2000)
return enrichSoil()
end
-- Enrich the soil or return an error if out peat, sand, etc.
function enrichSoil()
start = TIME
ContextMenu(pileID, "Enrich Soil")
sleep(1000)
if JournalScanner(start, TIME, {"not have any"}) then
return "Ran out of Soil Enricher"
end
return addFertilizer()
end
-- Add fertilizer until successful or return an error if out
function addFertilizer()
repeat
start = TIME
ContextMenu(pileID, "Add Fertilizer")
sleep(1000)
if JournalScanner(start, TIME, {"not have any"}) then
return "Ran out of Fish"
end
until JournalScanner(start, TIME, {"successfully fertilizes", "already Fertilized"})
return plantSeed()
end
-- Plant a seed until sucessful, incrementing through the seed ID numbers - returning an error if out of seeds
function plantSeed()
ContextMenu(pileID, "Plant Seeds")
repeat
sleep(1000)
start = TIME
ClickButton("GardenUI", tostring(seedIDNumberLow))
sleep(1000)
if JournalScanner(start, TIME, {"not have any"}) and seedIDNumberLow <= seedIDNumberHigh then
seedIDNumberLow = seedIDNumberLow + 1
if seedIDNumberLow > seedIDNumberHigh then return "Ran out of Seeds" end
ContextMenu(pileID, "Plant Seeds")
end
FindItem(" enriched soil")
until not FINDITEM
sleep(1000)
return waterPlant()
end
-- Water the plant or return an error if out of water
function waterPlant()
start = TIME
ContextMenu(pileID, "Water Plant")
sleep(1000)
if JournalScanner(start, TIME, {"not have any"}) then
return "Ran out of Water"
end
return "Successfully Planted"
end
-- Start of the script
getBounds()
for x = lowestx, highestx, 1.5 do
for z = lowestz, highestz, 1.5 do
message = startPlantingAt(x, z)
print(message)
if message != "Successfully Planted" then return end
sleep(3000)
end
end
print("Finished Planting!")