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
  • My Woodcutting bot is only clicking and cutting the tree once, I can't figure out the issue.


    Demauen

    Recommended Posts

    It could be because of this:

    GameObject yewTree = getGameObjects().closest("Yew");
    

    Your script is searching for nearest Yew, it does't matter if this tree is outside of your area. Use filters to fix this. Look at Towlie's post.

    Hey thanks for the tip, so I tried it with Towlie's code for finding the tree within the area but the same thing still happens. Once the tree is chopped down my character starts running back and forth a few tiles.

    Link to comment
    Share on other sites

    Hey thanks for the tip, so I tried it with Towlie's code for finding the tree within the area but the same thing still happens. Once the tree is chopped down my character starts running back and forth a few tiles.

    Can you send your actual code please

    Link to comment
    Share on other sites

    Can you send your actual code please

    Yeah sure here it is:

     

    package Main;
    
    import org.dreambot.api.methods.Calculations;
    import org.dreambot.api.methods.map.Area;
    import org.dreambot.api.methods.map.Tile;
    import org.dreambot.api.script.AbstractScript;
    import org.dreambot.api.script.Category;
    import org.dreambot.api.script.ScriptManifest;
    import org.dreambot.api.wrappers.interactive.Entity;
    import org.dreambot.api.wrappers.interactive.GameObject;
    import org.dreambot.api.wrappers.interactive.NPC;
    
    import java.awt.*;
    
    
    @ScriptManifest(category = Category.WOODCUTTING, name = "Woodcutter", author = "Demauen", version = 1.0)
    
    public class WoodCutter extends AbstractScript {
    
    
    Area bankArea = new Area(3092, 3242, 3092, 3245, 0);
    Area logArea = new Area(3056, 3270, 3052, 3273, 0);
    
    
    @Override
    public void onStart() {
    
    }
    
    
    
    @Override
    public int onLoop() {
    getCamera().rotateTo(6603, 6385);
    
    
    
    
    if (logArea.contains(getLocalPlayer())) {
    cutWood();
    } else if(!logArea.contains(getLocalPlayer())) {
    getWalking().walk(logArea.getRandomTile());
    
    }
    
    
    
    
    if (getInventory().isFull()) {
    if (!bankArea.contains(getLocalPlayer())) {
    
    if (getWalking().walk(bankArea.getRandomTile())) {
    sleep(Calculations.random(3760, 6360));
    }
    bank();
    }
    }
    
    return (Calculations.random(3200, 5500));
    }
    
    @Override
    public void onExit() {
    
    
    }
    
    @Override
    public void onPaint(Graphics graphics) {
    
    }
    
    private void cutWood() {
    GameObject yewTree = getGameObjects().closest(g -> g != null && g.getName().equals("Yew" ) && logArea.contains(getLocalPlayer()));
    
    yewTree.interact("Chop down");
    
    if (yewTree != null && yewTree.interact()) {
    while (yewTree.exists()) {
    sleep(Calculations.random(500, 1250));
    }
    }
    
    
    
    }
    
    private void bank() {
    
    NPC banker = getNpcs().closest(npc -> npc != null && npc.hasAction("Bank"));
    if (banker.interact("Bank")) {
    if (sleepUntil(() -> getBank().isOpen(), Calculations.random(2854, 8294))) {
    
    
    getBank().depositAllExcept("Rune axe");
    }
    }
    }
    
    }
    
    
    

    I usually have the camera rotation code commented out but just added it in for now.

     

    Link to comment
    Share on other sites

    Yeah sure here it is:

     

    package Main;
    
    import org.dreambot.api.methods.Calculations;
    import org.dreambot.api.methods.map.Area;
    import org.dreambot.api.methods.map.Tile;
    import org.dreambot.api.script.AbstractScript;
    import org.dreambot.api.script.Category;
    import org.dreambot.api.script.ScriptManifest;
    import org.dreambot.api.wrappers.interactive.Entity;
    import org.dreambot.api.wrappers.interactive.GameObject;
    import org.dreambot.api.wrappers.interactive.NPC;
    
    import java.awt.*;
    
    
    @ScriptManifest(category = Category.WOODCUTTING, name = "Woodcutter", author = "Demauen", version = 1.0)
    
    public class WoodCutter extends AbstractScript {
    
    
    Area bankArea = new Area(3092, 3242, 3092, 3245, 0);
    Area logArea = new Area(3056, 3270, 3052, 3273, 0);
    
    
    @Override
    public void onStart() {
    
    }
    
    
    
    @Override
    public int onLoop() {
    getCamera().rotateTo(6603, 6385);
    
    
    
    
    if (logArea.contains(getLocalPlayer())) {
    cutWood();
    } else if(!logArea.contains(getLocalPlayer())) {
    getWalking().walk(logArea.getRandomTile());
    
    }
    
    
    
    
    if (getInventory().isFull()) {
    if (!bankArea.contains(getLocalPlayer())) {
    
    if (getWalking().walk(bankArea.getRandomTile())) {
    sleep(Calculations.random(3760, 6360));
    }
    bank();
    }
    }
    
    return (Calculations.random(3200, 5500));
    }
    
    @Override
    public void onExit() {
    
    
    }
    
    @Override
    public void onPaint(Graphics graphics) {
    
    }
    
    private void cutWood() {
    GameObject yewTree = getGameObjects().closest(g -> g != null && g.getName().equals("Yew" ) && logArea.contains(getLocalPlayer()));
    
    yewTree.interact("Chop down");
    
    if (yewTree != null && yewTree.interact()) {
    while (yewTree.exists()) {
    sleep(Calculations.random(500, 1250));
    }
    }
    
    
    
    }
    
    private void bank() {
    
    NPC banker = getNpcs().closest(npc -> npc != null && npc.hasAction("Bank"));
    if (banker.interact("Bank")) {
    if (sleepUntil(() -> getBank().isOpen(), Calculations.random(2854, 8294))) {
    
    
    getBank().depositAllExcept("Rune axe");
    }
    }
    }
    
    }
    
    
    

    I usually have the camera rotation code commented out but just added it in for now.

     

     

    One problem seems to be that you are checking if the player is within the logArea in your filter where you grab the tree rather than checking if the tree is within the log area.

     

    In other words, you have this

    GameObject yewTree = getGameObjects().closest(g -> g != null && g.getName().equals("Yew" ) && logArea.contains(getLocalPlayer()));
    

    but what you should use is this

    GameObject yewTree = getGameObjects().closest(g -> g != null && g.getName().equals("Yew" ) && logArea.contains(g));
    
    Link to comment
    Share on other sites

     

    One problem seems to be that you are checking if the player is within the logArea in your filter where you grab the tree rather than checking if the tree is within the log area.

     

    In other words, you have this

    GameObject yewTree = getGameObjects().closest(g -> g != null && g.getName().equals("Yew" ) && logArea.contains(getLocalPlayer()));
    

    but what you should use is this

    GameObject yewTree = getGameObjects().closest(g -> g != null && g.getName().equals("Yew" ) && logArea.contains(g));
    

    Oh okay thanks! I'll try changing it and see if it helps. EDIT: It worked thanks dude but now for some reason rather than running away once the bot has cut down the tree maybe like 5-10 times it just stops detecting the tree and just stands there I think it could be from these lines:

     

    if (yewTree != null && yewTree.interact()) {
    while (yewTree.exists()) {
    sleep(Calculations.random(500, 1250));
    }
    Link to comment
    Share on other sites

     

    Oh okay thanks! I'll try changing it and see if it helps. EDIT: It worked thanks dude but now for some reason rather than running away once the bot has cut down the tree maybe like 5-10 times it just stops detecting the tree and just stands there I think it could be from these lines:

     

    if (yewTree != null && yewTree.interact()) {
    while (yewTree.exists()) {
    sleep(Calculations.random(500, 1250));
    }

     

     

    Sometimes the interaction will fail even if it returns true, so the tree will never be cut down.  You should use a sleepuntil with a timeout instead of a infinite while loop.

     

     

     Better yet, design your script so it doesn't rely on conditional sleeps.  Conditional sleeps are resource intensive and should be avoided, it's not necessary here.

    Link to comment
    Share on other sites

    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.