Jump to content
View in the app

A better way to browse. Learn more.

OSBot :: 2007 OSRS Botting

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Few questions I need help with

Featured Replies

I made a thread asking for help yesterday and got the help, i'm unsure if I'm suppose to continue that thread or make a new one so I decided to make a new one. If this was wrong please tell me.

So I got two questions.
1.  line 62 I get a warning with "getBank().depositAllExcept(axes -> axes.getName().contains(" axe"));" says multiple markers at this line. I can do "@SuppressWarnings("unchecked")" to remove that warning but I would rather see if it's something I need to get fixed and fix it the correct way. How would I do it?

2. I have read about a word I don't remember what it was but it had to do with splitting the script into smaller .java files I think and having like one Main one and then maybe one for Woodcutting, one for banking and one for paint.
I have no clue at all how to do this so if someone could link me a tutorial or try to explain this to me I would greatly appreciate that!

Thanks for all the help I can get!


package core;
import java.awt.Color;
import java.awt.Graphics2D;
//import java.awt.Image;
//import java.io.IOException;
//import java.net.URL;
import java.time.LocalTime;
import java.util.concurrent.TimeUnit;

//import javax.imageio.ImageIO;

import org.osbot.rs07.api.map.Area;
import org.osbot.rs07.api.map.constants.Banks;
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;

@ScriptManifest(name = "Woodcutting", version = 1.0, author = "HeyImJamie", info = "", logo = "")
public class Main extends Script {

    private long timeBegan;
    private long timeRan; 
    private int beginningXp;
    private int currentXp;
    private int xpGained;
    private int currentLevel;
    private int beginningLevel;
    private int levelsGained;
    //private final Image bg = getImage("https://i.imgur.com/rgIR2OP.png");
    
    @Override
    public void onStart() {
        timeBegan = System.currentTimeMillis();
        beginningXp = skills.getExperience(Skill.WOODCUTTING); 
        beginningLevel = skills.getStatic(Skill.WOODCUTTING);
    }
    
    @Override
    public int onLoop() throws InterruptedException {

        if (shouldBank()) {
            bank();
        } else {
            cutTree(getTreeName());
        }
        return 100;
    }

    private boolean shouldBank() {
        return getInventory().isFull();
    }

    @SuppressWarnings("unchecked")
    private void bank() throws InterruptedException {
        if (!Banks.DRAYNOR.contains(myPlayer())) {
            getWalking().webWalk(Banks.DRAYNOR);
        } else {
            if (!getBank().isOpen()) {
                getBank().open();
            } else {
                getBank().depositAllExcept(axes -> axes.getName().contains(" axe"));
            }
        }
    }

    private void cutTree(String treeName) {
        if (!getTreeArea().contains(myPlayer())) {
            getWalking().webWalk(getTreeArea());
        } else {
            RS2Object tree = getObjects().closest(getTreeArea(), getTreeName());
            if (!myPlayer().isAnimating() && tree != null) {
                if (tree.interact("Chop down")) {
                    new ConditionalSleep(5000) {
                        @Override
                        public boolean condition() throws InterruptedException {
                            return myPlayer().isAnimating();
                        }
                    }.sleep();
                }
            }
        }
    }

    private Area getTreeArea() {
        if (getSkills().getDynamic(Skill.WOODCUTTING) >= 60) {
            return new Area(3203, 3506, 3225, 3497);
        } else {
            return new Area(3091, 3239, 3076, 3230);
        }
    }

    private String getTreeName() {
        if (getSkills().getDynamic(Skill.WOODCUTTING) >= 60){
            return "Yew";
        } else if (getSkills().getDynamic(Skill.WOODCUTTING) >= 30){
            return "Willow";
        } else if (getSkills().getDynamic(Skill.WOODCUTTING) >= 15){
            return "Oak";
        } else {
            return "Tree";
        }
    }

@Override
    public void onPaint(Graphics2D g) {
    g.setColor(Color.BLACK);
    //background
    //g.drawImage(bg, 26, 108, null);
    //time
    timeRan = System.currentTimeMillis() - this.timeBegan; 
    g.drawString("Run time: "+ft(timeRan), 390, 400);
    //xp
    currentXp = skills.getExperience(Skill.WOODCUTTING); 
    xpGained = currentXp - beginningXp; 
    g.drawString("Gained " + xpGained + " Xp", 390, 380);
    //levels
    currentLevel = skills.getStatic(Skill.WOODCUTTING);
    levelsGained = currentLevel - beginningLevel;
    g.drawString(beginningLevel + " / " + currentLevel + " ( +" + levelsGained + " )", 390, 360);
    }
private String ft(long duration) 
{
    return LocalTime.ofSecondOfDay(TimeUnit.MILLISECONDS.toSeconds(duration)).toString();
}
/*private Image getImage(String url)
{
  try
  {
    return ImageIO.read(new URL(url));
  }
  catch (IOException e) {}
  return null;
}*/

}

  • Author

extending this with another question, how do I customize walkpaths I would rather select my own tiles/area of tiles to let the bot click in. Thanks

Edited by dunderzutt

Quote

1.  line 62 I get a warning with "getBank().depositAllExcept(axes -> axes.getName().contains(" axe"));" says multiple markers at this line. I can do "@SuppressWarnings("unchecked")" to remove that warning but I would rather see if it's something I need to get fixed and fix it the correct way. How would I do it?

This isn't something you necessarily need to fix or can fix. Bank::depositAllExcept is an overloaded method, and you're using the one with a varargs of Filter<Item>, meaning an array of item filters. Filter is a generic type, so you can create Filter<Item> to filter items or Filter<Player> to filter players and so on, but the issue arises because generics have a loss of information at compile time due to type erasure. At runtime, the only information available is there is an array of Filters, not specifically an array of Filter<Item>. In the method body of Bank::depositAllExcept(Filter<Item>...) I'd assume it checks the type of each Filter to ensure it is indeed an Item filter in order to behave as intended.

Here is an example of passing an array of filters that compiles fine, but throws a ClassCastException at runtime because a Player filter can't be cast to an Item filter.

Filter<Player> playerFilter = player -> player.isVisible();
Filter<Item> itemFilter = item -> item.getName().contains(" axe");
Filter[] filters = new Filter[] {
	playerFilter,
	itemFilter
};
getBank().depositAllExcept(filters);

So to answer the question, it's fine to suppress the warning as long as you ensure the filters being passed can be cast to the desired type in the method declaration.
Further reading: http://www.angelikalanger.com/GenericsFAQ/FAQSections/ProgrammingIdioms.html#FAQ300

Quote

2. I have read about a word I don't remember what it was but it had to do with splitting the script into smaller .java files I think and having like one Main one and then maybe one for Woodcutting, one for banking and one for paint.

You typically only want one class to do one thing. Not sure if this is what you're referring to by a word: https://en.wikipedia.org/wiki/SOLID
 

Quote

extending this with another question, how do I customize walkpaths I would rather select my own tiles/area of tiles to let the bot click in.

You can easily get coordinates of positions and areas using this: https://explv.github.io/

  • Author
Quote

You typically only want one class to do one thing. Not sure if this is what you're referring to by a word: https://en.wikipedia.org/wiki/SOLID

No that's not the word I was refering to but that doesn't matter. Yeah I think classes is what I meant. In my mind I see it working as I put onpaint things in a paint.class and then call them from the Main file. Is that correct?

Thanks for the answers to the other questions! much appreciated.

Quote

In my mind I see it working as I put onpaint things in a paint.class and then call them from the Main file. Is that correct?

The way I would design paint implementation is to keep specific paint operations in their related class. So a Woodcutting class may have its specific paint operations that displays xp gained, number of logs collected, etc. You may also have SomeOtherClass that displays its own specific information that is unrelated to the operations of the Woodcutting class. It is much easier to debug this way if some portion of the paint works unexpectedly, as well as keeping it organized. Doing it this way you can add or remove specific painters depending on what is needed.

If at script start it should display both the Woodcutting painter and SomeOtherClass painter, you would add them to the bot's painter list like

getBot().addPainter(Woodcutting.getPainter());
getBot().addPainter(SomeOtherClass.getPainter());

If at any point it's not necessary to display a specific painter, you would remove it with

getBot().removePainter(SomeOtherClass.getPainter());

 

Create an account or sign in to comment

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.