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.

Get current tree

Featured Replies

Is there a way to get the id of the tree that is CURRENTLY being chopped, so that if this one is cut down, it looks for the next tree. Also i need this method to be run every 5 sec. 

How do I do this?

  • Author

What does the sout line do?

EDIT: what does it even mean?

Edited by Dick

What does the sout line do?

EDIT: what does it even mean?

 

What i wrote its not code its snippet. sout = System.out.println which prints things to console. (system one)

Edited by PolishCivil


import org.osbot.script.Script;

import org.osbot.script.ScriptManifest;

import org.osbot.script.rs2.map.Position;

import org.osbot.script.rs2.model.RS2Object;

import org.osbot.script.rs2.utility.Condition;

import java.awt.*;

import java.util.List;

/**

* Created by Robert on 2014-04-18.

* Tip: if you want to get trees fast you will need to dump tree positions data.

* Like you walk to cutting area, dump positions of trees you want to cut, and then you can get objects by:

* client.getCurrentRegion().instance.getTiles()[position.getZ()][localX][localY].getObjects();

* Its alot faster.

*/

@ScriptManifest(name = "Simple chopper", info = "", author = "PolishCivil", version = 1.0D)

public class Chopper extends Script {

final static int[] WOODCUTTING_ANIMS_IDS = new int[]{

867, 868, 869, 870, 871, 872, 873, 874, 875, 876, 877, 878, 879, 880

};

private String treeName = "Tree";

private RS2Object currentTree = null, nextTree = null;

private long lastChopTime;

@Override

public int onLoop() throws InterruptedException {

if (isChoppingTree()) {

lastChopTime = System.currentTimeMillis();

}

if (currentTree == null || !currentTree.exists()) {

log("Searching for: " + treeName);

if (nextTree != null && nextTree.exists()) {

currentTree = nextTree;

} else {

currentTree = getClosestTree(null);

}

if (currentTree == null) {

warn("Couldt find - " + treeName);

return 2500;

}

/*

We are chopping tree now because getting next tree takes a while, so we are saving time.

*/

chopTree();

nextTree = getClosestTree(currentTree.getPosition());

return 300;

}

if (System.currentTimeMillis() - lastChopTime > 2000) {

chopTree();

} else {

return 600;

}

return 100;

}

/**

* Interacts with tree

*

* @throws InterruptedException

*/

private void chopTree() throws InterruptedException {

if (currentTree.interact("Chop down")) {

int dist = distance(currentTree);

if (waitFor(dist * 600 + 1000, new Condition() {

@Override

public boolean evaluate() {

return isChoppingTree() || (currentTree == null || !currentTree.exists());

}

})) {

lastChopTime = System.currentTimeMillis();

}

}

}

@Override

public void onPaint(Graphics a) {

Graphics2D g2d = (Graphics2D) a;

if (currentTree != null && currentTree.exists()) {

Polygon polygon = currentTree.getPosition().getPolygon(bot);

Rectangle bounds = polygon.getBounds();

String text = "Current";

g2d.drawString(text, (int) (bounds.getCenterX() - (g2d.getFontMetrics().stringWidth(text) / 2)), (int) bounds.getCenterY());

g2d.draw(polygon);

}

if (nextTree != null && nextTree.exists() && !currentTree.equals(nextTree)) {

Polygon polygon = nextTree.getPosition().getPolygon(bot);

Rectangle bounds = polygon.getBounds();

String text = "Next";

g2d.drawString(text, (int) (bounds.getCenterX() - (g2d.getFontMetrics().stringWidth(text) / 2)), (int) bounds.getCenterY());

g2d.draw(polygon);

}

}

/**

* Gets closest tree around player.

*

* @param exclude - the position exclude - we dont want tree at this position.

* @return - tree object.

*/

private RS2Object getClosestTree(Position exclude) {

List<RS2Object> rs2Objects = closestObjectListForName(treeName);

RS2Object closest = null;

for (RS2Object rs2Object : rs2Objects) {

if ((closest == null || distance(rs2Object) < distance(closest)) && (exclude == null || rs2Object.getPosition().distance(exclude) != 0)) {

closest = rs2Object;

}

}

return closest;

}

/**

* Checks if player is chopping tree.

*

* @return whether he is.

*/

private boolean isChoppingTree() {

for (int i : WOODCUTTING_ANIMS_IDS) {

if (myPlayer().getAnimation() == i) {

return true;

}

}

return false;

}

/**

* Waits for condition.

*

* @param time - the max time to wait.

* @param c - the condition to check.

* @return - whether condition evaluated successfuly.

*/

public boolean waitFor(int time, Condition c) {

for (int i = 0; (i < time / 50) && !c.evaluate(); i++) {

try {

sleep(50);

} catch (InterruptedException ignore) {

}

}

return c.evaluate();

}

}

What does the sout line do?

EDIT: what does it even mean?

how are you writing scripts if you don't know what syso/sout is?

Its just shortcut, it means nothing.

its the first thing you know when learning basic java....

its the first thing you know when learning basic java....

A shorthand way of doing something just depends on the program you're using. It's completely different in IntelliJ :facep:

Shit I didn't know what sout was when I first saw I though it was like shout out. So does that make me a nub

its the first thing you know when learning basic java....

I'm not sure where you learnt Java, but I didn't learn it by reading my IDE's shortcut manual.

I'm not sure where you learnt Java, but I didn't learn it by reading my IDE's shortcut manual.

university.

Well not everyone understands eachothers shortcuts/abbreviations so when explaining it's always good to use the generic term ^_^

Guest
This topic is now closed to further replies.

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.