Jump to content

Simple woodcutting script.


Xiwi

Recommended Posts

Hello!

I just got into botting and I decided to make my first script.

It's a simple woodcutting script, that cuts oaks at the back of the lumbridge castle and banks them in the upstairs bank. It has a simple paint with how much xp you have gained, how many levels gained, how many logs you have chopped and how much gold you have made. If you want to chop something else you can change the cutting area, banking area and what kind of tree to chop in the code. 

 

How to use:

Equip your axe.

Start near lumbridge castle.

Press play and it starts chopping!

 

Paint and small proggy

wcprog.png.5b8d000998617fdd4300188f45cbb84a.png

 

I decided to post this script for everyone, so that if there's anyone who might want to get into making scripts, they can look at what I have done and copy some of that.

 

Because this was my first script i'm open to feedback! Please point out if I should have made something differently.

 

Codes .jar download link. Place this into your OSbot script folder: C:\Users\yourprofilename\OSBot\Scripts

 

Sorry about this long code line. Didn't know to to make it hide.

Code: 

Spoiler

import org.osbot.rs07.api.map.Area;
import org.osbot.rs07.api.map.constants.Banks;
import org.osbot.rs07.api.model.Entity;
import org.osbot.rs07.api.model.RS2Object;
import org.osbot.rs07.api.ui.Skill;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;
import org.osbot.rs07.utility.ConditionalSleep;

import javax.imageio.ImageIO;
import java.awt.*;
import java.io.IOException;
import java.net.URL;
import java.text.DecimalFormat;
import java.util.concurrent.TimeUnit;

@ScriptManifest(name = "Xiwi's Woodcutter", version = 1.0, author = "Xiwi", logo = "https://i.imgur.com/ZlQD7PIt.png", info = "Cuts wood and banks it.")
public class Main extends Script {
    
    //Areas. You can pick your area easily with this: "https ://explv.github.io/".
    private final Area treeArea = new Area(3172, 3262, 3192, 3245);
    private final Area lumbridgeBankArea = new Area(3208, 3218, 3209, 3219);

    //Paint variables.
    private long timeBegan;
    private long timeRan;

    private int currentXp;
    private int xpGained;
    private int beginningXp;
    private int currentLevel;
    private int beginningLevel;
    private int levelsGained;

    private int costOfItem;
    private int itemsMade = 0;
    private double gpGained;
    private double totalGpGained;
    private double oakXp = 37.5;

    //Background image.
    private final Image bg = getImage("https://i.imgur.com/ZnxtQe1.png");


    @Override
    public void onStart() throws InterruptedException {
        //Anything place on here in here is played when script is started.
        beginningXp = skills.getExperience(Skill.WOODCUTTING);
        beginningLevel = skills.getStatic(Skill.WOODCUTTING);
        timeBegan = System.currentTimeMillis();
        costOfItem = 42; //Price of the logs.
    }

    @Override
    public int onLoop() throws InterruptedException {
        //Anything placed here keeps looping.
        if (getInventory().getEmptySlotCount() != 0) {
            RS2Object tree = getObjects().closest(obj -> obj != null && obj.getName().equals("Oak") && getMap().canReach(obj)); //What tree to chop.
            if (!myPlayer().isAnimating()) {
                if (tree != null) {
                    if (tree.interact("Chop down")) {
                        new ConditionalSleep(5000, 2000) {
                            @Override
                            public boolean condition() throws InterruptedException {
                                return false;
                            }
                        }.sleep();
                    }
                } else if (tree == null) {  //If it doesn't see a tree it moves the camera and then moves.
                    getCamera().toEntity(tree);
                    log("Searching for a tree...");
                    if (getWalking().webWalk(treeArea)) {
                        log("Walking to trees...");
                        new ConditionalSleep(5000, 6000) {
                            @Override
                            public boolean condition() throws InterruptedException {
                                return false;
                            }
                        };
                    }
                }
            }
        } else {
            log("Inventory full."); //Walks to the bank.
                if (getWalking().webWalk(Banks.LUMBRIDGE_UPPER)) { //What bank it banks at.
                    log("Walking to bank...");
                    new ConditionalSleep(5000, 1000) {
                        @Override
                        public boolean condition() throws InterruptedException {
                        return true;}
                    };
                    Entity depoBox = objects.closest("Bank deposit box"); //Opens deposit box and deposits logs.
                    if (depoBox != null) {
                        new ConditionalSleep(2000, 5000) {
                            @Override
                            public boolean condition() throws InterruptedException {
                                return true;
                            }
                        };
                        if (depoBox.interact("Deposit")) {
                            while (!depositBox.isOpen()) {
                                new ConditionalSleep(2000, 5000) {
                                    @Override
                                    public boolean condition() throws InterruptedException {
                                        return true;
                                    }
                                };
                            } depositBox.depositAllExcept("Bronze axe");

                        }
                    }
                }
            }
    return 1000;}

    @Override
    public void onExit () throws InterruptedException {
        //Anything placed here executes when the script stops.
        log("Chopped: ");
        log(itemsMade);
        log("Made: ");
        log(gpGained);
    }

    @Override
    public void onPaint (Graphics2D g) {
        //Text font, color, size.
        Font font = new Font("Consolas", Font.BOLD, 15);
        g.setFont(font);
        g.setFont(g.getFont().deriveFont(15.0f));
        g.setColor(Color.yellow);
        Graphics2D gr = g;

        //Background.
        g.drawImage(bg, -3, 335, null);

        //Script run time.
        timeRan = System.currentTimeMillis() - this.timeBegan;
        g.drawString("Time ran for: ", 40,395);
        g.drawString(ft(timeRan), 150, 395);

        //XP tracking and displaying.
        currentXp = skills.getExperience(Skill.WOODCUTTING);
        xpGained = currentXp - beginningXp;
        g.drawString("XP Gained: " + xpGained, 40, 420);
        levelsGained = currentLevel - beginningLevel;
        currentLevel = skills.getStatic(Skill.WOODCUTTING);
        g.drawString("Levels gained:" + levelsGained,260, 420);
        g.drawString("(" + beginningLevel,  383, 420 );
        g.drawString(")", 407, 420);

        //How many logs chopped and profits,´.
        itemsMade = (int) (xpGained / oakXp);
        gpGained = itemsMade * costOfItem;
        totalGpGained = gpGained / 1000;
        DecimalFormat df = new DecimalFormat("#");
        g.drawString("Gold made: " + df.format(totalGpGained) + " k", 260,445);
        g.drawString("Logs chopped: " + df.format(itemsMade), 40,445);
    }

    private String ft(long duration) //Makes time 0:0:0
    {

        String res = "";
        long days = TimeUnit.MILLISECONDS.toDays(duration);
        long hours = TimeUnit.MILLISECONDS.toHours(duration)
                - TimeUnit.DAYS.toHours(TimeUnit.MILLISECONDS.toDays(duration));
        long minutes = TimeUnit.MILLISECONDS.toMinutes(duration)
                - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS
                .toHours(duration));
        long seconds = TimeUnit.MILLISECONDS.toSeconds(duration)
                - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS
                .toMinutes(duration));
        if (days == 0) {
            res = (hours + ":" + minutes + ":" + seconds);
            } else {
            res = (days + ":" + hours + ":" + minutes + ":" + seconds);
        }
        return res;
    }
    private Image getImage(String url) //Get's the background image.
    {
        try
        {
            return ImageIO.read(new URL(url));
        }
        catch (IOException e) {}
        return null;
    }
}

Edited by Xiwi
Added a spoiler for the code
Link to comment
Share on other sites

Nice work on your first script only thing I really see that could be changed is;

else if (tree == null) {  //If it doesn't see a tree it moves the camera and then moves.
                    getCamera().toEntity(tree);
                    log("Searching for a tree...");
                    if (getWalking().webWalk(treeArea)) {
                        log("Walking to trees...");
                        new ConditionalSleep(5000, 6000) {
                            @Override
                            public boolean condition() throws InterruptedException {
                                return false;
                            }
                        };
                    }
                }
            }

Should probably check if the tree isVisible() and not if it's null because if the tree is null then your trying to face a null object, also that sleep wouldn't work properly.

you should probably make it something like,

                        new ConditionalSleep(5000, 250) {
                            @Override
                            public boolean condition() throws InterruptedException {
                                return tree.isVisible();
                            }
                        };

 

Edited by 01053
Link to comment
Share on other sites

On 5/26/2018 at 1:52 PM, Xiwi said:

Hello!

I just got into botting and I decided to make my first script.

It's a simple woodcutting script, that cuts oaks at the back of the lumbridge castle and banks them in the upstairs bank. It has a simple paint with how much xp you have gained, how many levels gained, how many logs you have chopped and how much gold you have made. If you want to chop something else you can change the cutting area, banking area and what kind of tree to chop in the code. 

 

How to use:

Equip your axe.

Start near lumbridge castle.

Press play and it starts chopping!

 

Paint and small proggy

wcprog.png.5b8d000998617fdd4300188f45cbb84a.png

 

I decided to post this script for everyone, so that if there's anyone who might want to get into making scripts, they can look at what I have done and copy some of that.

 

Because this was my first script i'm open to feedback! Please point out if I should have made something differently.

 

Codes .jar download link. Place this into your OSbot script folder: C:\Users\yourprofilename\OSBot\Scripts

 

Sorry about this long code line. Didn't know to to make it hide.

Code: 


import org.osbot.rs07.api.map.Area;
import org.osbot.rs07.api.map.constants.Banks;
import org.osbot.rs07.api.model.Entity;
import org.osbot.rs07.api.model.RS2Object;
import org.osbot.rs07.api.ui.Skill;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;
import org.osbot.rs07.utility.ConditionalSleep;

import javax.imageio.ImageIO;
import java.awt.*;
import java.io.IOException;
import java.net.URL;
import java.text.DecimalFormat;
import java.util.concurrent.TimeUnit;

@ScriptManifest(name = "Xiwi's Woodcutter", version = 1.0, author = "Xiwi", logo = "https://i.imgur.com/ZlQD7PIt.png", info = "Cuts wood and banks it.")
public class Main extends Script {
    
    //Areas. You can pick your area easily with this: "https ://explv.github.io/".
    private final Area treeArea = new Area(3172, 3262, 3192, 3245);
    private final Area lumbridgeBankArea = new Area(3208, 3218, 3209, 3219);

    //Paint variables.
    private long timeBegan;
    private long timeRan;

    private int currentXp;
    private int xpGained;
    private int beginningXp;
    private int currentLevel;
    private int beginningLevel;
    private int levelsGained;

    private int costOfItem;
    private int itemsMade = 0;
    private double gpGained;
    private double totalGpGained;
    private double oakXp = 37.5;

    //Background image.
    private final Image bg = getImage("https://i.imgur.com/ZnxtQe1.png");


    @Override
    public void onStart() throws InterruptedException {
        //Anything place on here in here is played when script is started.
        beginningXp = skills.getExperience(Skill.WOODCUTTING);
        beginningLevel = skills.getStatic(Skill.WOODCUTTING);
        timeBegan = System.currentTimeMillis();
        costOfItem = 42; //Price of the logs.
    }

    @Override
    public int onLoop() throws InterruptedException {
        //Anything placed here keeps looping.
        if (getInventory().getEmptySlotCount() != 0) {
            RS2Object tree = getObjects().closest(obj -> obj != null && obj.getName().equals("Oak") && getMap().canReach(obj)); //What tree to chop.
            if (!myPlayer().isAnimating()) {
                if (tree != null) {
                    if (tree.interact("Chop down")) {
                        new ConditionalSleep(5000, 2000) {
                            @Override
                            public boolean condition() throws InterruptedException {
                                return false;
                            }
                        }.sleep();
                    }
                } else if (tree == null) {  //If it doesn't see a tree it moves the camera and then moves.
                    getCamera().toEntity(tree);
                    log("Searching for a tree...");
                    if (getWalking().webWalk(treeArea)) {
                        log("Walking to trees...");
                        new ConditionalSleep(5000, 6000) {
                            @Override
                            public boolean condition() throws InterruptedException {
                                return false;
                            }
                        };
                    }
                }
            }
        } else {
            log("Inventory full."); //Walks to the bank.
                if (getWalking().webWalk(Banks.LUMBRIDGE_UPPER)) { //What bank it banks at.
                    log("Walking to bank...");
                    new ConditionalSleep(5000, 1000) {
                        @Override
                        public boolean condition() throws InterruptedException {
                        return true;}
                    };
                    Entity depoBox = objects.closest("Bank deposit box"); //Opens deposit box and deposits logs.
                    if (depoBox != null) {
                        new ConditionalSleep(2000, 5000) {
                            @Override
                            public boolean condition() throws InterruptedException {
                                return true;
                            }
                        };
                        if (depoBox.interact("Deposit")) {
                            while (!depositBox.isOpen()) {
                                new ConditionalSleep(2000, 5000) {
                                    @Override
                                    public boolean condition() throws InterruptedException {
                                        return true;
                                    }
                                };
                            } depositBox.depositAllExcept("Bronze axe");

                        }
                    }
                }
            }
    return 1000;}

    @Override
    public void onExit () throws InterruptedException {
        //Anything placed here executes when the script stops.
        log("Chopped: ");
        log(itemsMade);
        log("Made: ");
        log(gpGained);
    }

    @Override
    public void onPaint (Graphics2D g) {
        //Text font, color, size.
        Font font = new Font("Consolas", Font.BOLD, 15);
        g.setFont(font);
        g.setFont(g.getFont().deriveFont(15.0f));
        g.setColor(Color.yellow);
        Graphics2D gr = g;

        //Background.
        g.drawImage(bg, -3, 335, null);

        //Script run time.
        timeRan = System.currentTimeMillis() - this.timeBegan;
        g.drawString("Time ran for: ", 40,395);
        g.drawString(ft(timeRan), 150, 395);

        //XP tracking and displaying.
        currentXp = skills.getExperience(Skill.WOODCUTTING);
        xpGained = currentXp - beginningXp;
        g.drawString("XP Gained: " + xpGained, 40, 420);
        levelsGained = currentLevel - beginningLevel;
        currentLevel = skills.getStatic(Skill.WOODCUTTING);
        g.drawString("Levels gained:" + levelsGained,260, 420);
        g.drawString("(" + beginningLevel,  383, 420 );
        g.drawString(")", 407, 420);

        //How many logs chopped and profits,´.
        itemsMade = (int) (xpGained / oakXp);
        gpGained = itemsMade * costOfItem;
        totalGpGained = gpGained / 1000;
        DecimalFormat df = new DecimalFormat("#");
        g.drawString("Gold made: " + df.format(totalGpGained) + " k", 260,445);
        g.drawString("Logs chopped: " + df.format(itemsMade), 40,445);
    }

    private String ft(long duration) //Makes time 0:0:0
    {

        String res = "";
        long days = TimeUnit.MILLISECONDS.toDays(duration);
        long hours = TimeUnit.MILLISECONDS.toHours(duration)
                - TimeUnit.DAYS.toHours(TimeUnit.MILLISECONDS.toDays(duration));
        long minutes = TimeUnit.MILLISECONDS.toMinutes(duration)
                - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS
                .toHours(duration));
        long seconds = TimeUnit.MILLISECONDS.toSeconds(duration)
                - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS
                .toMinutes(duration));
        if (days == 0) {
            res = (hours + ":" + minutes + ":" + seconds);
            } else {
            res = (days + ":" + hours + ":" + minutes + ":" + seconds);
        }
        return res;
    }
    private Image getImage(String url) //Get's the background image.
    {
        try
        {
            return ImageIO.read(new URL(url));
        }
        catch (IOException e) {}
        return null;
    }
}

very inpressive for a first script :)

Link to comment
Share on other sites

  • 3 weeks later...
On 6/1/2018 at 5:53 AM, 01053 said:

Nice work on your first script only thing I really see that could be changed is;


else if (tree == null) {  //If it doesn't see a tree it moves the camera and then moves.
                    getCamera().toEntity(tree);
                    log("Searching for a tree...");
                    if (getWalking().webWalk(treeArea)) {
                        log("Walking to trees...");
                        new ConditionalSleep(5000, 6000) {
                            @Override
                            public boolean condition() throws InterruptedException {
                                return false;
                            }
                        };
                    }
                }
            }

Should probably check if the tree isVisible() and not if it's null because if the tree is null then your trying to face a null object, also that sleep wouldn't work properly.

you should probably make it something like,


                        new ConditionalSleep(5000, 250) {
                            @Override
                            public boolean condition() throws InterruptedException {
                                return tree.isVisible();
                            }
                        };

 

Okay thanks for the tip! ?

On 6/1/2018 at 10:39 AM, TheMcPker said:

very inpressive for a first script :)

Thank you! ? Going to make something much better (at least hope so) once I find the time to code ?

Link to comment
Share on other sites

  • 5 years later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...