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
  • Made my first script, but there's an issue?


    Awesomemite

    Recommended Posts

    Posted

    I've been working on a simple woodcutter. And until yesterday I had no experience coding java - I've done a little R programming but that's about it. I've been reading some tutorials on here and figured I'd make a woodcutter that banks. 

    However, I can't seem to make the player cut wood after he returns from the bank. It only walks to the area and then stops - returning "Waiting" from my code. What did I do wrong? 

     

    Code is posted: 

    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.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.NPC;
    
    
    @ScriptManifest(author = "Awesomemite", category = Category.WOODCUTTING, description = "Cuts wood for f2p", image = "",
            name = "BasicWoodCutter",version = 10.0)
    public class Main extends AbstractScript {
    
        Area chopArea = new Area(3131,3439,3148,3421);
        Area bankArea = new Area(3180,3446,3186,3434);
        public void onStart (){
            log("Welcome to the simple woodcutter!");
        }
        private enum State{
            Chop, Bank, WalkToBank,Walktochop, Wait,
        }
    
        private State getState(){
            if (getInventory().isEmpty() && !getLocalPlayer().isAnimating() && chopArea.contains(getLocalPlayer()))
                return State.Chop;
            if (bankArea.contains(getLocalPlayer()) && getInventory().isFull())
                return State.Bank;
            if (getInventory().isFull())
                return State.WalkToBank;
            if (bankArea.contains(getLocalPlayer()) && getInventory().isEmpty())
                return State.Walktochop;
            return State.Wait;
        }
    
        @Override
        public int onLoop() {
            switch (getState()) {
                case Chop:
                    GameObject tree = getGameObjects().closest("Tree", "Oak");{
                    if(tree != null) {
                        tree.interact("Chop down");
                    }
                }
                    break;
                case Bank:
                    getNpcs().closest("Banker").interact("Bank");{
                        getBank().depositAllExcept(item -> item != null && item.getName().contains(" axe"));
                }
                    break;
                case WalkToBank:
                    getWalking().walk(BankLocation.VARROCK_WEST.getCenter());
                    break;
                case Walktochop:
                    getWalking().walk(chopArea.getCenter());
                    break;
                case Wait:
                    log("Waiting");
                    break;
            }
            return Calculations.random(1000,5000);
        }
    }

     

    Posted

    According to your code logic, it would only return a chopping state if your inventory is completely empty and you are within the woodcutting area. If you inventory contains anything at all, it could cause this issue. I would instead check if inventory is not full, then chop.

    Even if the bot misclicked and out you outside of both the bank or chop area, it would result in your wait state.

    Just a lot of things you need to account for 

    • 1 month later...

    Archived

    This topic is now archived and is closed to further replies.

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