Jump to content
View in the app

A better way to browse. Learn more.

OSBot :: 2007 OSRS Botting

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Walking to local objects, iterate though them?

Featured Replies

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

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.
  • Author

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.

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.

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.

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

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.