Dick Posted April 17, 2014 Posted April 17, 2014 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?
PolishCivil Posted April 17, 2014 Posted April 17, 2014 private RS2Object tree;onloop: if(tree==null || !tree.exists()) tree = closestRs2ObjectForName("Tree);sout("tree id: "+tree.getId());
Dick Posted April 17, 2014 Author Posted April 17, 2014 (edited) What does the sout line do? EDIT: what does it even mean? Edited April 17, 2014 by Dick
PolishCivil Posted April 17, 2014 Posted April 17, 2014 (edited) 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 April 17, 2014 by PolishCivil
PolishCivil Posted April 17, 2014 Posted April 17, 2014 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(); } }
Novak Posted April 17, 2014 Posted April 17, 2014 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? 1
PolishCivil Posted April 17, 2014 Posted April 17, 2014 how are you writing scripts if you don't know what syso/sout is? Its just shortcut, it means nothing.
Novak Posted April 17, 2014 Posted April 17, 2014 Its just shortcut, it means nothing. its the first thing you know when learning basic java....
Swizzbeat Posted April 17, 2014 Posted April 17, 2014 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
PolishCivil Posted April 17, 2014 Posted April 17, 2014 its the first thing you know when learning basic java.... Do you know DISHsfshfasfSDHjfsdjnf ? Its my shortcut to System.out.println You nub. 2
Joseph Posted April 18, 2014 Posted April 18, 2014 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
Pseudo Posted April 18, 2014 Posted April 18, 2014 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.
Novak Posted April 18, 2014 Posted April 18, 2014 I'm not sure where you learnt Java, but I didn't learn it by reading my IDE's shortcut manual. university.
Booch Posted April 18, 2014 Posted April 18, 2014 Well not everyone understands eachothers shortcuts/abbreviations so when explaining it's always good to use the generic term ^_^