Gmachine88
Member
- Joined
- Oct 28, 2012
- Messages
- 120
- Reaction score
- 0
So, during downtime this morning, I felt like writing an Auto Farm script that's as generic/simple as possible for easy adaptation to suit your needs.
I'll admit now that I haven't actually tested it due to the fact my 3day trial key has ran out. (Sorry if it's not perfect)
Fell free to use and abuse this code as much as you like . It's by no way complete, as there is no pause between runs, yet it should get you on your feet and on your way to your own custom script to suit your farm.
I'll do my best to answer any questions / problems, but without my current access to AB, it'll be mainly guess work on my behalf.
# The code has plenty of comments for you to follow along with what's supposed to be happening.
# Naturally, you will need to change the values in the variable section at the top to meet your needs.
# The Only 2 'Merchant Locations' used in this example are SeedMerch and WaterWell.
EDIT:
Wow, finally got my hands on AB again and boy did that script have some compile errors. Testing it out now.
I'll admit now that I haven't actually tested it due to the fact my 3day trial key has ran out. (Sorry if it's not perfect)
Fell free to use and abuse this code as much as you like . It's by no way complete, as there is no pause between runs, yet it should get you on your feet and on your way to your own custom script to suit your farm.
Code:
using System;
using System.Drawing;
using System.Windows.Forms;
using System.Threading;
using System.Collections.Generic;
using System.Linq;
using ArcheBuddy.Bot.Classes;
namespace AutoFarmer{
//- Our Main Class
public class Main : Core
{
//- Variables
//- Basics
private string Owner1 = ""; //- First Farm Owner Name
private string Owner2 = ""; //- Second Farm Owner Name
private int MinLabor = 500; //- MINIMUM amount of Labor Required to run
//- Important Locations
private float[] SeedMerch = {0,0,0}; //- X,Y,Z values of Seed Merchant Location
private float[] SapMerch = {0,0,0}; //- X,Y,Z values of Sapling Merchant Location
private float[] GenMerch = {0,0,0}; //- X,Y,Z values of General Merchant Location
private float[] LiveMerch = {0,0,0}; //- X,Y,Z values of Livestock Merchant Location
private float[] WaterWell = {0,0,0}; //- X,Y,Z values of Water Well Location
private float[] Warehouse = {0,0,0}; //- X,Y,Z values of Warehouse Location (Doubles up as Mail Box Location)
private float[] Auctioneer = {0,0,0}; //- X,Y,Z values of Auctioneer Location
//- Crop Specifics
//- These next couple of arrays will need to match the order
private int[] SeedCount = {20,15}; //- How many we want to plant each time: For me (Aloe, Rye)
private bool[] BuySeed = {false,false}; //- Are we buying seed types? (Aloe,Rye)
//- General Infomation about the Plugin
public static string GetPluginAuthor()
{
return "Gmachine88";
}
public static string GetPluginVersion()
{
return "1.0.0.0";
}
public static string GetPluginDescription()
{
return "Auto Feed, Harvest, Plant and Water your farms!";
}
//- Start Plugin
public void PluginRun()
{
/*
Please Note: I've decided to treat each Farm as seperate subroutines
This method can be less efficient due to travel times to Vendors etc
However, its also easier to organise for first time users.
*/
int RunCounter = 0;
ClearLogs();
Log("Auto Farm Start!"); // Start Log Message
//- Initiate main loop
while (true)
{
//- Get Current LAbor Points
int LP = me.laborPoints;
if(LP < MinLabor)
{
//- Not enough Labor. Initiate Anti-AFK Mode
}else{
//- Run First Farm
RunCounter += 1;
Log("Initiating Run Number: " + RunCounter);
Farm1();
Farm2();
//- Add any extra farms here
}
}
}
//- Stopped Plugin
public void PluginStop()
{
Log("AutoFarm has stopped!"); // Stop
}
//- Call this to gather more water
public void WaterPump()
{
// Count Water
Item InvItem = getInvItem("Water");
Log("You currently have " + InvItem.count + " Water.");
// Check we need water
if(InvItem.count < 100)
{
// Move to Well
MoveTo(WaterWell[0], WaterWell[1], WaterWell[2]);
}
//- Thanks to CoalCloud for this code! (https://www.thebuddyforum.com/archebuddy-forum/archebuddy-plugins/other/186595-release-gather-water.html)
while(InvItem.count < 100)
{
DoodadObject well = getDoodads().FirstOrDefault(x => x.dist(me) <= 5d && x.name == "Well");
if (well == null)
return;
while (me.isCasting || me.isGlobalCooldown) ;
List<Skill> sList;
while ((sList = well.getUseSkills()).Count == 0) ;
UseDoodadSkill(sList[0].id, well, true);
}
}
//- The following Subroutines should make it easier for you to copy / paste to match your own farming ideas
//- I made a seperate subroutine for each of my farms
public void Farm1()
{
//- First Let's Deal with Animals
CollectItemsAtFarm("Small Goose Cage", "Husbandry: Spend 1 Labor and 3 Ground Grain to feed livestock.", Owner1);
CollectItemsAtFarm("Small Goose Cage", "Husbandry: Spend up to 50 Labor to collect feathers from the cage. Has a low chance of shattering the cage completely.", Owner1);
//- Crop Harvest Time
//- This Section assumes we want to plant a specific number of seeds each time we've harvested them
//- Long, detailed version
//- Step 1: Check our current supply of Harvested Crop (This acts as our check if we need more seeds)
int s = (int)itemCount("Aloe");
//- Step 2: Harvest the Crop
CollectItemsAtFarm("Aloe", "Gathering: Spend up to 2 Labor to gather materials.", Owner1);
//- Step 3: Compare to oringal count
int e = (int)itemCount("Aloe");
if(e > s)
{
//- We have harvested, therefore need seeds
BuySeed[0] = true; //- Set first Crops buy mode to true
Log("Harvested : " + (e - s) + " Aloe.");
}else{
BuySeed[0] = false; //- Just incase it was still set to true from the previous run
}
//- Short version
s = (int)itemCount("Mature Rye");
CollectItemsAtFarm("Mature Rye", "Farming: Spend up to 2 Labor to harvest crops.", "Owner1");
e = (int)itemCount("Mature Rye");
if(e > s)
{
BuySeed[1] = true;
Log("Harvested : " + (e - s) + " Rye.");
}else{
BuySeed[1] = false; //- Just incase it was still set to true from the previous run
}
//- Now it's time to buy new seeds and gather up some water before planting
//- Check our water situation
WaterPump();
//- Now lets get some more seeds
MoveTo(SeedMerch[0],SeedMerch[1],SeedMerch[2]);
//- Check our seed needs
//- For ease of reading, I've done each one individually rather than in a loop
if(BuySeed[0]) //- First crop (Aloe for me)
{
s = (int)itemCount("Aloe Seedling");
if(s < SeedCount[0])
{
// Need to buy more seeds
BuyItems("Aloe Seedling", SeedCount[0]- s);
}
}
if(BuySeed[1]) //- Second crop (Rye for me)
//- Notice how the number inside the [ ] matches up in each section
{
s = (int)itemCount("Rye Seedling");
if(s < SeedCount[1])
{
// Need to buy more seeds
BuyItems("Rye Seedling", SeedCount[1]- s);
}
}
//- Now we have our seeds, lets go plant and water them
PlantItemsAtFarm("Aloe Seed", Owner1);
CollectItemsAtFarm("Aloe Seedling", "Water a plant and help it grow.", Owner1);
PlantItemsAtFarm("Rye Seed", Owner1);
CollectItemsAtFarm("Rye Seedling", "Water a plant and help it grow.", Owner1);
//- We have now finished dealing with our first farm.
}
public void Farm2()
{
//- This version will be less detailed, comment wise.
//- Not sure if the Hungry version is correct, which is why i commented it out
// CollectItemsAtFarm("Hungry Goose", "Husbandry: Spend up to 5 Labor to shear livestock.", Owner2);
CollectItemsAtFarm("Goose", "Husbandry: Spend 1 Labor and 1 Ground Grain to feed livestock.", Owner2);
CollectItemsAtFarm("Thriving Goose", "Husbandry: Spend up to 5 Labor to shear livestock.", Owner2);
// CollectItemsAtFarm("Hungry Hen", "Husbandry: Spend up to 5 Labor to shear livestock.", Owner2);
CollectItemsAtFarm("Hen", "Husbandry: Spend 1 Labor and 1 Ground Grain to feed livestock.", Owner2);
CollectItemsAtFarm("Thriving Hen", "Husbandry: Spend up to 5 labor to gather eggs.", Owner2);
//- I don't have crops on this farm, but I'll write Farm1 crop as an example
int s = (int)itemCount("Aloe");
CollectItemsAtFarm("Aloe", "Gathering: Spend up to 2 Labor to gather materials.", Owner2);
int e = (int)itemCount("Aloe");
if(e > s)
{
BuySeed[0] = true;
Log("Harvested : " + (e-s) + " Aloe.");
}else{
BuySeed[0] = false;
}
s = (int)itemCount("Mature Rye");
CollectItemsAtFarm("Mature Rye", "Farming: Spend up to 2 Labor to harvest crops.", "Owner2");
e = (int)itemCount("Mature Rye");
if(e > s)
{
BuySeed[1] = true;
Log("Harvested : " + (e-s) + " Rye.");
}else{
BuySeed[1] = false;
}
WaterPump();
MoveTo(SeedMerch[0],SeedMerch[1],SeedMerch[2]);
if(BuySeed[0])
{
s = (int)itemCount("Aloe Seedling");
if(s < SeedCount[0])
{
BuyItems("Aloe Seedling", SeedCount[0]- s);
}
}
if(BuySeed[1])
{
s = (int)itemCount("Rye Seedling");
if(s < SeedCount[1])
{
BuyItems("Rye Seedling", SeedCount[1]- s);
}
}
PlantItemsAtFarm("Aloe Seed", Owner2);
CollectItemsAtFarm("Aloe Seedling", "Water a plant and help it grow.", Owner2);
PlantItemsAtFarm("Rye Seed", Owner2);
CollectItemsAtFarm("Rye Seedling", "Water a plant and help it grow.", Owner2);
//- Finished
}
//- Add more Farms if necessary, don't forget to call them in the PluginRun section
public void Farm3()
{
}
}
}
I'll do my best to answer any questions / problems, but without my current access to AB, it'll be mainly guess work on my behalf.
# The code has plenty of comments for you to follow along with what's supposed to be happening.
# Naturally, you will need to change the values in the variable section at the top to meet your needs.
# The Only 2 'Merchant Locations' used in this example are SeedMerch and WaterWell.
EDIT:
Wow, finally got my hands on AB again and boy did that script have some compile errors. Testing it out now.
Last edited: