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.

"duplicate" objects?

Featured Replies

package org;


import org.osbot.rs07.api.map.Position;
import org.osbot.rs07.api.model.RS2Object;
import org.osbot.rs07.script.Plugin;

import java.util.Comparator;
import java.util.List;
import java.util.function.Predicate;
import java.util.stream.Collectors;

public class Test extends Plugin {
    public String treeToCut = "Tree";

    private Predicate<RS2Object> suitableObj = n ->
            n.getName().equals(treeToCut) &&
                    getMap().canReach(n) &&
                    getMap().distance(n) < 4;

    private java.util.List<RS2Object> treeObjs;

    @Override
    public int onLoop() throws InterruptedException {
        log("onLoop: ");

        List<RS2Object> allObjs = getObjects().getAll();
        log("getObjects().getAll().size(): " + allObjs.size());

        int count = 0;
        for(RS2Object obj : allObjs){
            if (obj.getName().equals(treeToCut) && getMap().distance(obj) < 4) {
                log("AAA " + obj.getX() + " " + obj.getY());
                count++;
            }
        }
        log("count: " + count);


        treeObjs = getObjects().getAll().stream().filter(suitableObj).collect(Collectors.toList());

        if (!treeObjs.isEmpty()) {
            log("treeObjs.size(): " + treeObjs.size());
            treeObjs.sort(Comparator.<RS2Object>comparingInt(a -> getMap().distance(a)).thenComparingInt(b -> getMap().distance(b)));
            log("sort treeObjs.size(): " + treeObjs.size());

            treeObjs.forEach(obj -> log(obj.getX() + " " + obj.getY()));
        } else {
            log("treeObjs.isEmpty()");
        }


        return 2000;
    }


}
onLoop: 
getObjects().getAll().size(): 8618
AAA 3163 3454
AAA 3163 3454
AAA 3163 3454
AAA 3163 3454
count: 4
treeObjs.size(): 4
sort treeObjs.size(): 4
3163 3454
3163 3454
3163 3454
3163 3454

Why? What is the meaning and different of these "duplicate" objects?

Thanks:)

Edited by Pegasus

Just a guess, but it may be that Objects#getAll iterates the coordinates of the region graph, adding all InteractableObjects found. If this is the case, the result might be that an object of 2x2 size (large object that spans 4 tiles) would be added multiple times, as it can be found on multiple coordinates, even though the objects 'anchor position' is the same.

Depending on whether or not they're the same object instance, using Collectors.toSet might function as a workaround

Edited by FrostBug

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.