This script will provide a robust woodcutting experience using the Dreambot 3 API. It includes a state machine for managing the script's flow, banking functionality, and basic paint for displaying statistics.
Key Features:
- State Machine: Manages the script's current action (chopping, walking to bank, banking, walking to trees, equipping axe).
- Axe Handling: Ensures you have an axe equipped or in your inventory. Prioritizes the best axe you have.
- Dynamic Tree Finding: Finds the nearest available tree to chop.
- Smart Banking: Walks to a specified bank area, opens the bank, deposits all items except your axe, and closes the bank.
- Area Definitions: Uses
RSArea to define the woodcutting spot and bank area, making it adaptable to different locations.
- Robust Interaction: Uses
RSTime.sleepUntil for more reliable interactions (waiting for animation, bank to open, etc.) rather than fixed sleeps.
- Paint Statistics: Displays runtime, logs cut, experience gained, and XP/hour.
- Logging: Provides detailed information in the Dreambot console.
Dreambot 3 Woodcutting Script: Ultimate Chopper
import org.dreambot.api.methods.Calculations;
import org.dreambot.api.methods.container.impl.bank.BankLocation;
import org.dreambot.api.methods.map.Area;
import org.dreambot.api.methods.map.Tile;
import org.dreambot.api.methods.walking.path.impl.LocalPath;
import org.dreambot.api.script.AbstractScript;
import org.dreambot.api.script.Category;
import org.dreambot.api.script.ScriptManifest;
import org.dreambot.api.wrappers.interactive.GameObject;
import org.dreambot.api.wrappers.interactive.Item;
import org.dreambot.api.wrappers.interactive.Player;
import org.dreambot.api.wrappers.interactive.NPC;
import java.awt.*;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.Random;
import java.util.stream.Collectors;
@ScriptManifest(
name = "Ultimate Chopper",
description = "Chops wood and deposits it to the bank. Adaptable to different locations.",
author = "YourDreambotName", // Replace with your Dreambot username
version = 1.1,
category = Category.WOODCUTTING,
image = "" // Optional: Path to an image file for your script
)
public class UltimateChopper extends AbstractScript {
// --- Configuration ---
private static final String[] TREE_NAMES = {"Tree", "Oak", "Willow", "Maple tree", "Yew", "Magic tree"}; // Order by priority if you want specific trees
private static final String[] AXE_NAMES = { // Order from best to worst
"Dragon axe", "Infernal axe", "Rune axe", "Adamant axe", "Mithril axe",
"Black axe", "Steel axe", "Iron axe", "Bronze axe"
};
// Replace these with your desired areas!
// Example: Lumbridge trees and Lumbridge castle bank
private final Area WOODCUTTING_AREA = new Area(3232, 3219, 3209, 3252); // Lumbridge trees
private final Area BANKING_AREA = new Area(3207, 3217, 3213, 3219); // Lumbridge Castle bank area (inside)
private final Tile BANK_TILE = new Tile(3208, 3219, 0); // Specific tile near the bank booth
// --- Script Variables ---
private State currentState;
private long startTime;
private int startWoodcuttingLevel;
private int startWoodcuttingExp;
private int logsCut;
// --- State Enum ---
private enum State {
EQUIPPING_AXE,
WALKING_TO_TREES,
CHOPPING,
WALKING_TO_BANK,
BANKING,
IDLE // For error or waiting
}
@Override
public void onStart() {
log.info("Ultimate Chopper has started!");
startTime = System.currentTimeMillis();
startWoodcuttingLevel = getSkills().getRealLevel(org.dreambot.api.methods.skills.Skill.WOODCUTTING);
startWoodcuttingExp = getSkills().getExperience(org.dreambot.api.methods.skills.Skill.WOODCUTTING);
logsCut = 0;
currentState = State.EQUIPPING_AXE; // Start by ensuring axe is ready
}
@Override
public int onLoop() {
// Anti-ban & General Checks
if (getLocalPlayer().isAnimating() || getLocalPlayer().isMoving()) {
return Calculations.random(100, 300); // Short pause while player is busy
}
switch (currentState) {
case EQUIPPING_AXE:
handleEquippingAxe();
break;
case WALKING_TO_TREES:
handleWalkingToTrees();
break;
case CHOPPING:
handleChopping();
break;
case WALKING_TO_BANK:
handleWalkingToBank();
break;
case BANKING:
handleBanking();
break;
case IDLE:
log.info("Script is idle. Re-evaluating...");
sleep(1000); // Short sleep to prevent spam
// Try to recover by going back to the first state that checks conditions
if (getInventory().isFull()) {
currentState = State.WALKING_TO_BANK;
} else if (!hasAxe()) {
currentState = State.EQUIPPING_AXE;
} else {
currentState = State.WALKING_TO_TREES;
}
break;
}
return Calculations.random(200, 500); // Main loop sleep
}
private void handleEquippingAxe() {
if (isAxeEquipped()) {
log.info("Axe is already equipped. Transitioning to WALKING_TO_TREES.");
currentState = State.WALKING_TO_TREES;
return;
}
Item axeInInventory = getBestAxeInInventory();
if (axeInInventory != null) {
log.info("Found " + axeInInventory.getName() + " in inventory. Equipping...");
if (axeInInventory.interact("Wield")) {
sleepUntil(this::isAxeEquipped, 3000);
}
} else {
log.error("No suitable axe found in inventory or equipped! Stopping script.");
stop();
}
}
private void handleWalkingToTrees() {
if (WOODCUTTING_AREA.contains(getLocalPlayer())) {
log.info("Already in woodcutting area. Transitioning to CHOPPING.");
currentState = State.CHOPPING;
return;
}
log.info("Walking to woodcutting area: " + WOODCUTTING_AREA.getCenter().toString());
if (getWalking().walk(WOODCUTTING_AREA.getCenter())) {
sleepUntil(() -> WOODCUTTING_AREA.contains(getLocalPlayer()) || !getLocalPlayer().isMoving(), 5000);
} else {
log.error("Failed to walk to woodcutting area.");
currentState = State.IDLE;
}
}
private void handleChopping() {
if (getInventory().isFull()) {
log.info("Inventory is full. Transitioning to WALKING_TO_BANK.");
currentState = State.WALKING_TO_BANK;
return;
}
if (!isAxeEquipped() && getBestAxeInInventory() != null) {
log.warn("Axe unequipped while chopping. Re-equipping.");
currentState = State.EQUIPPING_AXE;
return;
}
GameObject tree = getGameObjects().closest(gameObject -> {
if (gameObject == null || !gameObject.hasAction("Chop")) return false;
String name = gameObject.getName();
return name != null && Arrays.asList(TREE_NAMES).contains(name) && gameObject.canReach();
});
if (tree != null) {
log.info("Found tree: " + tree.getName() + " at " + tree.getTile().toString() + ". Chopping...");
int initialLogCount = getInventory().count(item -> item != null && item.getName().endsWith("logs"));
if (tree.interact("Chop")) {
sleepUntil(() -> getLocalPlayer().isAnimating() || getInventory().count(item -> item != null && item.getName().endsWith("logs")) > initialLogCount, 6000); // Wait for anim or log
sleep(600, 1000); // Short delay after starting chop to prevent misclicks/spam
long startTimeChop = System.currentTimeMillis();
// Wait until not animating, or tree is gone, or inventory is full
sleepUntil(() -> !getLocalPlayer().isAnimating() || !tree.exists() || getInventory().isFull(), 30000); // Max 30s per tree
int currentLogCount = getInventory().count(item -> item != null && item.getName().endsWith("logs"));
if (currentLogCount > initialLogCount) {
logsCut += (currentLogCount - initialLogCount);
log.info("Gained " + (currentLogCount - initialLogCount) + " logs.");
} else if (!tree.exists()) {
log.info("Tree chopped down/despawned.");
}
} else {
log.warn("Failed to interact with tree. Retrying...");
currentState = State.IDLE; // Could be stuck, re-evaluate
}
} else {
log.warn("No suitable trees found nearby. Moving to a new spot or waiting.");
// If no trees are found, move to a random tile within the chopping area
if (WOODCUTTING_AREA.contains(getLocalPlayer())) {
Tile randomTile = WOODCUTTING_AREA.getRandomTile();
if (randomTile != null && getWalking().walk(randomTile)) {
sleepUntil(() -> getLocalPlayer().isMoving() && getLocalPlayer().getTile().distance(randomTile) < 5, 3000);
}
}
currentState = State.WALKING_TO_TREES; // Force re-evaluation of area
}
}
private void handleWalkingToBank() {
if (BANKING_AREA.contains(getLocalPlayer())) {
log.info("Already in banking area. Transitioning to BANKING.");
currentState = State.BANKING;
return;
}
log.info("Walking to banking area: " + BANK_TILE.toString());
if (getWalking().walk(BANK_TILE)) {
sleepUntil(() -> BANKING_AREA.contains(getLocalPlayer()) || !getLocalPlayer().isMoving(), 7000);
} else {
log.error("Failed to walk to banking area.");
currentState = State.IDLE;
}
}
private void handleBanking() {
if (!getInventory().isFull() && getInventory().contains(item -> item != null && item.getName().endsWith("logs"))) {
log.info("Inventory not full of logs but still has logs. Ensuring deposit.");
// Continue to bank even if not strictly full, but has logs
} else if (!getInventory().contains(item -> item != null && item.getName().endsWith("logs"))) {
log.info("No logs to deposit. Transitioning to WALKING_TO_TREES.");
currentState = State.WALKING_TO_TREES;
return;
}
GameObject bankBooth = getGameObjects().closest("Bank booth", "Bank chest", "Grand Exchange booth", "Banker");
if (bankBooth != null) {
log.info("Found bank booth. Opening bank.");
if (bankBooth.interact("Bank")) {
sleepUntil(() -> getBank().isOpen(), 5000);
if (getBank().isOpen()) {
log.info("Bank is open. Depositing all logs except axe.");
List<String> axeNames = Arrays.asList(AXE_NAMES);
if (getBank().depositAllExcept(item -> axeNames.contains(item.getName()))) {
sleepUntil(() -> !getInventory().contains(item -> item != null && item.getName().endsWith("logs")), 3000);
if (!getInventory().contains(item -> item != null && item.getName().endsWith("logs"))) {
log.info("Logs deposited successfully.");
if (getBank().close()) {
sleepUntil(() -> !getBank().isOpen(), 2000);
log.info("Bank closed. Transitioning to WALKING_TO_TREES.");
currentState = State.WALKING_TO_TREES;
} else {
log.warn("Failed to close bank. Retrying banking.");
}
} else {
log.error("Failed to deposit all logs. Retrying banking.");
}
} else {
log.error("Failed to send deposit all command. Retrying banking.");
}
} else {
log.warn("Bank did not open after interaction. Retrying banking.");
}
} else {
log.warn("Failed to interact with bank booth. Retrying banking.");
}
} else {
log.warn("No bank booth found nearby. Walking closer to bank area or re-evaluating.");
currentState = State.WALKING_TO_BANK; // Force a re-walk if bank not found
}
}
@Override
public void onPaint(Graphics2D g) {
long runTime = System.currentTimeMillis() - startTime;
long hours = runTime / (1000 * 60 * 60);
long minutes = (runTime / (1000 * 60)) % 60;
long seconds = (runTime / 1000) % 60;
int currentWoodcuttingLevel = getSkills().getRealLevel(org.dreambot.api.methods.skills.Skill.WOODCUTTING);
int currentWoodcuttingExp = getSkills().getExperience(org.dreambot.api.methods.skills.Skill.WOODCUTTING);
int expGained = currentWoodcuttingExp - startWoodcuttingExp;
double expPerHour = (expGained / (double) runTime) * 3600000;
double logsPerHour = (logsCut / (double) runTime) * 3600000;
g.setColor(new Color(0, 0, 0, 150)); // Semi-transparent black background
g.fillRect(10, 30, 200, 120);
g.setColor(Color.WHITE);
g.setFont(new Font("Arial", Font.PLAIN, 12));
int y = 45;
g.drawString("Ultimate Chopper v" + getScriptManifest().version(), 15, y);
y += 15;
g.drawString("Runtime: " + String.format("%02d:%02d:%02d", hours, minutes, seconds), 15, y);
y += 15;
g.drawString("Logs Cut: " + logsCut, 15, y);
y += 15;
g.drawString("WC Level: " + startWoodcuttingLevel + " -> " + currentWoodcuttingLevel, 15, y);
y += 15;
g.drawString("XP Gained: " + expGained + " (" + String.format("%.2f", expPerHour / 1000) + "k XP/hr)", 15, y);
y += 15;
g.drawString("Logs/hr: " + String.format("%.0f", logsPerHour), 15, y);
y += 15;
g.drawString("State: " + currentState.name().replace("_", " "), 15, y);
}
// --- Helper Methods ---
private boolean hasAxe() {
return isAxeEquipped() || getBestAxeInInventory() != null;
}
private boolean isAxeEquipped() {
return getEquipment().isWearingItem(item -> Arrays.asList(AXE_NAMES).contains(item.getName()));
}
private Item getBestAxeInInventory() {
for (String axeName : AXE_NAMES) {
Item axe = getInventory().get(axeName);
if (axe != null) {
return axe;
}
}
return null;
}
// Overrides sleep for more robust delays
private void sleep(int min, int max) {
sleep(Calculations.random(min, max));
}
}
How to Use and Configure:
-
Save the Code: Save the Java code above as UltimateChopper.java in your Dreambot scripts folder.
-
Open Dreambot Client: Launch the Dreambot client.
-
Compile: Go to the "Script Manager" tab, find "Ultimate Chopper" in your local scripts, and click "Compile". Fix any errors if they appear (shouldn't if copied correctly).
-
Configure Areas:
- Crucial Step! The
WOODCUTTING_AREA, BANKING_AREA, and BANK_TILE are currently set to Lumbridge Castle and nearby trees. You MUST change these to your desired locations.
- How to get Area/Tile coordinates:
- In Dreambot, enable the "Developer Console" (usually F5 or by going to
Tools -> Developer Console).
- Go to the "Game Objects" tab or "Map" tab.
- For
Tile: Right-click on a specific tile on the game map in the client and select "Copy Tile". It will give you something like Tile(X, Y, Z). Use that for BANK_TILE.
- For
Area: This is a bit trickier. An Area can be defined by two opposing corners (new Area(x1, y1, x2, y2) for a rectangle) or a polygon.
- Walk to the top-left-most point of your desired woodcutting/banking area. Copy its tile coordinates.
- Walk to the bottom-right-most point of your desired woodcutting/banking area. Copy its tile coordinates.
- Create
new Area(x1, y1, x2, y2) using these two sets of coordinates.
- Example for Lumbridge:
new Area(3232, 3219, 3209, 3252) defines a rectangular area between (3209, 3219) and (3232, 3252).
- Adjust
TREE_NAMES and AXE_NAMES:
TREE_NAMES: Add or remove tree types based on what you want to cut. The order matters if you want to prioritize cutting certain trees first (e.g., if "Willow" is before "Tree", it will prefer willows).
AXE_NAMES: Ensure this list contains the names of axes you might use, from best to worst. The script will try to equip the best one you have.
-
Start the Script: Once compiled and configured, select "Ultimate Chopper" from the Script Manager and click "Start".
Important Notes:
- Starting Location: For best results, start the script either in your woodcutting area or reasonably close to it, and ensure you have an axe in your inventory or equipped.
- Anti-ban: This script includes basic sleep functions after actions and checks if the player is animating/moving. For long-term botting, consider integrating more advanced anti-ban compliance (e.g., random camera movements, mouse movements, more varied sleep patterns, reaction to random events, etc.). Dreambot's API provides methods for these.
- Error Handling: The script has logging for common errors (e.g., no axe, failed to walk, bank not found). If it gets stuck, check the Dreambot console for messages.
- Client Size: Ensure your RuneScape client size is large enough for Dreambot to correctly identify objects. A resolution like 765x503 (default fixed) or higher is usually good.
- Banking Location: The banking logic uses a
GameObject lookup. For BANKING_AREA, define the general vicinity of the bank, and for BANK_TILE, pick a specific tile near where the bank object is, so the script walks precisely towards it. The closest method will then find the interactable object.