GaetanoH Posted May 18, 2016 Share Posted May 18, 2016 So sometimes the scripts actually hovers the tree which is being cut, which I do not want and it's really inefficient. Can't really seem to fix it. if (getObjects().getAll().stream().filter(o -> o.getName().equals(gui.getTree())).count() >= 2) { if (nextTree == null || !nextTree.exists()) { nextTree = getObjects().closest(true, o -> o.getName().equals(gui.getTree()) && o != treeObject && cuttingArea.contains(o) && o.getPosition() != treeObject.getPosition()); } else if (!getMouse().isOnCursor(nextTree)) { nextTree.hover(); } } Quote Link to comment Share on other sites More sharing options...
Token Posted May 18, 2016 Share Posted May 18, 2016 Well, if I understand the context right, treeObject is supposed to be the current tree? If the value of nextTree is not assigned anywhere else then the code looks alright but you might be wrongly setting treeObject to the next tree that you want to cut somewhere else in the code and nextTree will be set to the one you are already cutting. Don't forget to treat the exception where your nextTree will be cut by another person before you get to switch trees. Quote Link to comment Share on other sites More sharing options...
Explv Posted May 18, 2016 Share Posted May 18, 2016 (edited) So sometimes the scripts actually hovers the tree which is being cut, which I do not want and it's really inefficient. Can't really seem to fix it. import org.osbot.rs07.api.model.RS2Object; import org.osbot.rs07.script.Script; import org.osbot.rs07.script.ScriptManifest; import org.osbot.rs07.utility.ConditionalSleep; @ScriptManifest(author = "Explv", name = "Example hover", info = "", version = 0.1, logo = "") public class Example extends Script { private enum State { CHOPPING, HOVERING } private RS2Object chopTree; @Override public int onLoop() throws InterruptedException { switch (getState()) { case CHOPPING: chop(); break; case HOVERING: hover(); break; } return random(200, 300); } private State getState() { if(chopTree == null || !chopTree.exists() || !myPlayer().isAnimating()) return State.CHOPPING; return State.HOVERING; } private void chop() { chopTree = getObjects().closest("Tree"); if(chopTree != null && chopTree.interact("Chop down")) { new ConditionalSleep(5000) { @Override public boolean condition() throws InterruptedException { return !chopTree.exists() || myPlayer().isAnimating(); } }.sleep(); } } private void hover() { RS2Object hoverTree = getObjects().closest(obj -> obj.getName().equals("Tree") && obj != chopTree); if(hoverTree != null && !getMouse().isOnCursor(hoverTree)) { hoverTree.hover(); } } } The logic is pretty simple: If the player is not woodcutting, find closest tree and chop it Else find the closest tree, that is not equal to the tree the player is chopping and hover it Edited May 18, 2016 by Explv 2 Quote Link to comment Share on other sites More sharing options...
Woody Posted May 18, 2016 Share Posted May 18, 2016 (edited) You make it too complicated.. Find the tree you are chopping Find the next, closest tree which you are not interacting with (myPlayer().getInteracting() != nextTree) Hover if cursor is not on it You should make the hovering randomized, otherwise it will be an ongoing pattern. Edited May 18, 2016 by Woody 2 Quote Link to comment Share on other sites More sharing options...
Chris Posted May 18, 2016 Share Posted May 18, 2016 You make it too complicated.. Find the tree you are chopping Find the next, closest tree which you are not interacting with (myPlayer().getInteracting() != nextTree) Hover if cursor is not on it You should make the hovering randomized, otherwise it will be a ongoing pattern. Quote Link to comment Share on other sites More sharing options...