Jump to content
Frequently Asked Questions
  • Are you not able to open the client? Try following our getting started guide
  • Still not working? Try downloading and running JarFix
  • Help! My bot doesn't do anything! Enable fresh start in client settings and restart the client
  • How to purchase with PayPal/OSRS/Crypto gold? You can purchase vouchers from other users
  • Try asking for help in the chatbox
  • Binary tree framework with action controller


    Recommended Posts

    Hi all,

    I've written a binary tree framework that does the following:

    • Fluent style quickly and easily define branches
    • Ability to continuously execute a leaf until it is done processing, so the tree doesn't need to be traversed each game loop

    Main files to look at:

    • src/example/WoodcutterTreeBuilder
    • src/example/WoodcutterScript
    • src/example/actions
    • src/framework


    Snippet - define branches

    package example;
    import example.actions.BankAction;
    import example.actions.WoodcuttingAction;
    import framework.*;
    import org.dreambot.api.methods.interactive.Players;
    public class WoodcutterTreeBuilder extends TreeBuilder<WoodcutterContext> {
    	private ActionController controller;
    	public WoodcutterTreeBuilder(WoodcutterContext context) {
    	public Node<WoodcutterContext> build(ActionController controller) {
    		this.controller = controller;
    		return inventoryIsFull();
    	private Node<WoodcutterContext> inventoryIsFull() {
    		return new Branch<WoodcutterContext>()
    				.validate(() -> Inventory.isFull()))
    				.success(new Leaf<WoodcutterContext>(new BankAction(controller, context)))
    				.fail(new Leaf<WoodcutterContext>(new WoodcuttingAction(controller, context)));


    Snippet define action (of a leaf)

    package example.actions;
    import example.WoodcutterContext;
    import framework.Action;
    import framework.ActionController;
    import org.dreambot.api.methods.MethodProvider;
    import org.dreambot.api.methods.container.impl.Inventory;
    import org.dreambot.api.methods.container.impl.bank.Bank;
    import org.dreambot.api.methods.interactive.Players;
    import org.dreambot.api.methods.walking.impl.Walking;
    public class BankAction extends Action<WoodcutterContext> {
    	public BankAction(ActionController actionController, WoodcutterContext context) {
    		super(actionController, context);
    	public int onLoop() {
    		if (context.bankArea.contains(Players.localPlayer())) {
    			if (Bank.isOpen()) {
    				if (Inventory.count(item -> !item.getName().toLowerCase().contains("axe")) > 0)	{
    					MethodProvider.log("Depositing all items except axe");
    					Bank.depositAllExcept(item -> item.getName().toLowerCase().contains("axe"));
    				} else {
    					MethodProvider.log("Closing bank");
    					// the action is now done, so tell controller to re-evaluate tree & get next action
    			} else {
    				MethodProvider.log("Opening bank");
    		} else {
    			MethodProvider.log("Walking to bank");
    			if (Walking.shouldWalk()) {
    			MethodProvider.sleepUntil(Walking::shouldWalk, Players.localPlayer()::isMoving, 3000, 500);
    		return 1000;
    	public void onStart() {


    Edited by jgs95
    Link to comment
    Share on other sites

    Create an account or sign in to comment

    You need to be a member in order to leave a comment

    Create an account

    Sign up for a new account in our community. It's easy!

    Register a new account

    Sign in

    Already have an account? Sign in here.

    Sign In Now

    • Create New...

    Important Information

    We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.