Hayase Posted December 17, 2016 Share Posted December 17, 2016 (edited) Hello! I'm making a woodcutting script that chops near Draynor. So far if a tree is off the map I am trying to get the script to run closer to that object. I've defined a global area the script will operate in and within that area I am trying to define and grab all local Oak trees. private Area tree_range = new Area(3096, 3210, 3142, 3220); RS2Object tree = api.objects.closest(tree_range, "Oak"); if (tree != null) { if (tree.isVisible()) { if (tree.interact("Chop Down")) { api.log("Chopping tree"); } } else { api.log("Adjusting camera to tree"); api.camera.toEntity(tree); api.log("Walking closer to tree"); WebWalkEvent webEvent = new WebWalkEvent(tree.getPosition()); webEvent.setEnergyThreshold(18); webEvent.useSimplePath(); webEvent.setBreakCondition(new Condition() { @[member='Override'] public boolean evaluate() { if (tree.isVisible()) { api.log("ChopTask: Tree is visible--condition met!"); return true; } else return false; } }); api.execute(webEvent); } } else { api.log("Tree is null"); } This doesn't go to the next tree (object) after the tree has been chopped down. Anyone have any advice to move onto the next (closest) tree in a local defined Area? Edited December 17, 2016 by Hayase Quote Link to comment Share on other sites More sharing options...
BoysNoize Posted December 17, 2016 Share Posted December 17, 2016 If you're cutting trees in a specific area, there's a couple things you could do: Hardcode the positions of the trees: Check distance to each of the positions to find closest, move to closest. Have the bot relocate to the centre of the area when it can't find any trees: You're never going to stray too far from the area, and you know you're always going to be near trees. Quote Link to comment Share on other sites More sharing options...
Hayase Posted December 17, 2016 Author Share Posted December 17, 2016 So I couldn't solve my problem elegantly so I just hard coded every tree location and calculated distance from each tree and decided which tree to cut next that way. I wanted to be more abstract with it so I could expand it to other trees in a designated area but maybe I'll figure it out in the future. Quote Link to comment Share on other sites More sharing options...
Xerifos Posted December 17, 2016 Share Posted December 17, 2016 Why does it have to walk to a specific tree? What I do is I let it webwalk to a location close to the object/npc then I let it check for the closest object/npc and it'll interact with it by itself without having to hardcode every position. Quote Link to comment Share on other sites More sharing options...
BoysNoize Posted December 17, 2016 Share Posted December 17, 2016 So I couldn't solve my problem elegantly so I just hard coded every tree location and calculated distance from each tree and decided which tree to cut next that way. I wanted to be more abstract with it so I could expand it to other trees in a designated area but maybe I'll figure it out in the future. Ah ok, there are ways you can make it more general. If you're always specifying an area, you can just walk to random points in the area and check for trees. If your area is x1=3096 y1=3210 x2=3142 y2=3220, you could just generate a random X to walk to between 3096 and 3142, and a random Y between 3210 and 3220. If you're not specifying an area, you could chuck in a parameter for the task to say "You can stray this far from the starting point", and then you could walk randomly anywhere in that area. Hardcoding is always going to be faster, but yeah, if you're trying to be more general this isn't a great solution. Quote Link to comment Share on other sites More sharing options...
progamerz Posted December 17, 2016 Share Posted December 17, 2016 (edited) U can use InteractionEvent? and why are u webwalking instead of Walking? http://osbot.org/api/org/osbot/rs07/event/InteractionEvent.html NPC tree = getNpcs().closest("Oak"); //(Entity entity, "action") InteractionEvent interactTree = new InteractionEvent(tree, "Chop Down"); //camera operation (boolean true || false) interactTree.setOperateCamera(true); //walking operation (boolean true || false) interactTree.setWalkTo(true); execute(interactTree); Edited December 17, 2016 by progamerz Quote Link to comment Share on other sites More sharing options...