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
  • Adding a Treebot option in API


    Michaudretard
     Share

    Recommended Posts

    Treebot are build with branch and leaf.

    First we have to create our root task in our main.java file. Then we return where our bot should start. In this case the bot should start at looking if inventory contain the ingredients.

    public class main extends TreeBot {
    
        private final inv_ingredient_check invIngredientCheck = new inv_ingredient_check();
    
        @Override
        public TreeTask createRootTask() {
            return invIngredientCheck;
        }
    
    }

    Branch are boolean build like this. We have the validate state that look for the true or false and we have the return statement (success and the failure).

    In this code we are looking if the bank contains grapes and jug of water. If the bank contains those item we return a success task and move on a branch task again or a leaf that execute code base on the true or false statement. If the bank doesn't contain those item we return the failure task and move on a branch task again or a leaf that execute code base on the true or false statement.
     

    public class bank_contain_ingredient extends BranchTask {
    
        private final inv_contain_something invContainSomething = new inv_contain_something();
        private final is_bank_close isBankClose = new is_bank_close();
    
        @Override
        public boolean validate() {
            return Bank.containsAllOf("Grapes", "Jug of water");
        }
    
        @Override
        public TreeTask successTask() {
            return invContainSomething;
        }
    
        @Override
        public TreeTask failureTask() {
            return isBankClose;
        }
    }

    Leaf execute code base on the returned boolean.

    public class close_bank extends LeafTask {
        @Override
        public void execute() {
            Bank.close();
        }
    }

     

    Link to comment
    Share on other sites

    On 8/29/2020 at 11:06 PM, Michaudretard said:

    Treebot are build with branch and leaf.

    First we have to create our root task in our main.java file. Then we return where our bot should start. In this case the bot should start at looking if inventory contain the ingredients.

    public class main extends TreeBot {
    
        private final inv_ingredient_check invIngredientCheck = new inv_ingredient_check();
    
        @Override
        public TreeTask createRootTask() {
            return invIngredientCheck;
        }
    
    }

    Branch are boolean build like this. We have the validate state that look for the true or false and we have the return statement (success and the failure).

    In this code we are looking if the bank contains grapes and jug of water. If the bank contains those item we return a success task and move on a branch task again or a leaf that execute code base on the true or false statement. If the bank doesn't contain those item we return the failure task and move on a branch task again or a leaf that execute code base on the true or false statement.
     

    public class bank_contain_ingredient extends BranchTask {
    
        private final inv_contain_something invContainSomething = new inv_contain_something();
        private final is_bank_close isBankClose = new is_bank_close();
    
        @Override
        public boolean validate() {
            return Bank.containsAllOf("Grapes", "Jug of water");
        }
    
        @Override
        public TreeTask successTask() {
            return invContainSomething;
        }
    
        @Override
        public TreeTask failureTask() {
            return isBankClose;
        }
    }

    Leaf execute code base on the returned boolean.

    public class close_bank extends LeafTask {
        @Override
        public void execute() {
            Bank.close();
        }
    }

     

    Yeah... this already exists.

     

    Extend TaskScript on your main class and TaskNode on your Nodes

    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
     Share

    ×
    ×
    • 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.