xxslasherrmx Posted February 17, 2016 Posted February 17, 2016 (edited) 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, 2016 by xxslasherrmx
xxslasherrmx Posted February 17, 2016 Author Posted February 17, 2016 Well.. Thank you very much! I glossed over this in the api
Extreme Scripts Posted February 17, 2016 Posted February 17, 2016 (edited) 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, 2016 by Extreme Scripts
xxslasherrmx Posted February 17, 2016 Author Posted February 17, 2016 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