February 17, 20169 yr I am a newbie working on my first woodcutting script, and everything is going good so far. However, using Objects.closest() sends the player on a wild Tree hunt as the nearest tree is a good distance away. How can I ensure that the bot only clicks on Trees inside the designated area? Thanks Edited February 17, 20169 yr by xxslasherrmx
February 17, 20169 yr private RS2Object tree; private Area someArea = new Area(x1, y1, x2, y2; public boolean chopTree(){ List<RS2Object> trees = getObjects().getAll().stream().filter(ob -> ob != null && ob.getName().equalsIgnoreCase("Tree") && canChop(ob)).collect(Collectors.toList()); if(!myPlayer().isAnimating() && trees.size() > 0){ RS2Object tree = trees.get(Script.random(trees.size())); if(tree.interact("Chop down"){ //sleep or something return true; } } return false; } public boolean canChop(RS2Object tree){ return someArea.contains(tree); } Alternative to @FrostBugs All code from my head so just double check. Edited February 17, 20169 yr by Extreme Scripts
February 17, 20169 yr Author Area trees = new Area(3145, 3492, 3141, 3500); Entity tree = objects.closest(trees, "Tree"); if(tree != null && !myPlayer().isAnimating() ){ tree.interact("Chop Down"); Worked like a charm
Create an account or sign in to comment