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

    So the script I have made for my Woodcutting bot doesen't fucntion properly, it runs to the woodcutting area finds the necesseray tree and clicks it. But after doing so once it no longer does it again and I cannot find what I'm doing wrong.

     

    Heres the script:


    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(3255, 3420, 3251, 3420, 0);
    Area logArea = new Area(3246, 3475, 3251, 3470, 0);
    
    
    @Override
    public void onStart() {
    
    }
    
    
    
    @Override
    public int onLoop() {
    
    
    
    
    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(1500, 3500));
    }
    
    @Override
    public void onExit() {
    
    
    }
    
    @Override
    public void onPaint(Graphics graphics) {
    
    }
    
    private void cutWood() {
    GameObject yewTree = getGameObjects().closest("Yew");
    
    yewTree.interact("Chop down");
    
    while (logArea.contains(getLocalPlayer())) {
    sleepUntil(() -> !getLocalPlayer().isAnimating(), Calculations.random(750, 2500));
    }
    
    
    }
    
    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");
    }
    }
    }
    
    }
    
    
    

     

    Link to comment
    Share on other sites

    Its because you never exit your while loop in the cutwood function. Try changing it to something like this.

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

    It would be best to use a sleepUntil without the while loop, but the above example should work if you really want to use a while. You could just replace the while loop with a sleepUntil using the opposite of the while condition "!yewTree.exists()".

    Link to comment
    Share on other sites

    Its because you never exit your while loop in the cutwood function. Try changing it to something like this.

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

    It would be best to use a sleepUntil without the while loop, but the above example should work if you really want to use a while. You could just replace the while loop with a sleepUntil using the opposite of the while condition "!yewTree.exists()".

    Oh okay! thanks for the help I appreciate it.

    Link to comment
    Share on other sites

    No problem! Best of luck with your script.

    So I found another issue with my script (The previous issue is fixed, once again thanks!) but for some reason my character runs away a few tiles when the tree is cut down then runs back, I don't want my bot to behave like that and I don't know what's causing it.

    Link to comment
    Share on other sites

    So I found another issue with my script (The previous issue is fixed, once again thanks!) but for some reason my character runs away a few tiles when the tree is cut down then runs back, I don't want my bot to behave like that and I don't know what's causing it.

    is the tree area you have big enough? could be that due to it not being in the area anymore (from interacting with the tree you just cutted) and due to that tries to walk into you're tree area again before finding a tree to cut

    Link to comment
    Share on other sites

    is the tree area you have big enough? could be that due to it not being in the area anymore (from interacting with the tree you just cutted) and due to that tries to walk into you're tree area again before finding a tree to cut

    I'll try changing it, thanks for the tip!

    Link to comment
    Share on other sites

    I'll try changing it, thanks for the tip!

    Also may want to add this too (More or less for future experiences if you plan to chop other trees too).

     

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

    is the tree area you have big enough? could be that due to it not being in the area anymore (from interacting with the tree you just cutted) and due to that tries to walk into you're tree area again before finding a tree to cut

    So I made the tree area big enough to contain me and the tree with certainty, But once the tree goes down my character still goes running aaway a few tiles and then back.

    Link to comment
    Share on other sites

    So I made the tree area big enough to contain me and the tree with certainty, But once the tree goes down my character still goes running aaway a few tiles and then back.

     

    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.

    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.