Jump to content

Walking to local objects, iterate though them?


Hayase
 Share

Recommended Posts

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
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

  • Recently Browsing   0 members

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