Jump to content

Walking to local objects, iterate though them?


Recommended Posts

Posted (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 by Hayase
Posted

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.
Posted

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.

Posted

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.

Posted (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 by progamerz

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...