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.

Filter's

Featured Replies

First of all you need to create an Interface

 

public interface Filter<T> {

	public boolean accept(T arg0);

}

Example usage of the Filter

import java.util.ArrayList;

import org.osbot.script.Script;
import org.osbot.script.rs2.model.GroundItem;
import org.osbot.script.rs2.model.NPC;
import org.osbot.script.rs2.model.RS2Object;
import utils.Filter;

public class ScrubUtils {

	private Script script;

	public ScrubUtils(Script script) {
		this.script = script;
	}

	public RS2Object[] getAllRS2Objects(Filter<RS2Object> filter) {
		ArrayList<RS2Object> array = new ArrayList<RS2Object>();
		for (RS2Object rs2o : script.client.getCurrentRegion().getObjects()) {
			if (!array.contains(rs2o) && filter.accept(rs2o)) {
				array.add(rs2o);
			}
		}
		return array.toArray(new RS2Object[array.size()]);

	}

	public GroundItem[] getAllGroundItems(Filter<GroundItem> filter) {
		ArrayList<GroundItem> array = new ArrayList<GroundItem>();
		for (GroundItem gi : script.client.getCurrentRegion().getItems()) {
			if (!array.contains(gi) && filter.accept(gi)) {
				array.add(gi);
			}
		}
		return array.toArray(new GroundItem[array.size()]);

	}

	public NPC[] getAllNPCS(Filter<NPC> filter) {
		ArrayList<NPC> array = new ArrayList<NPC>();
		for (NPC n : script.client.getLocalNPCs()) {
			if (!array.contains(n) && filter.accept(n)) {
				array.add(n);
			}
		}
		return array.toArray(new NPC[array.size()]);

	}

	public RS2Object[] getObjectsWithAction(final String action) {
		Filter<RS2Object> filter = new Filter<RS2Object>() {
			@Override
			public boolean accept(RS2Object t) {
				if (t != null) {
					if (t.getDefinition() != null) {
						if (t.getDefinition().getActions() != null) {
							if (t.getDefinition().getActions().length > 0) {
								for (String a : t.getDefinition().getActions()) {
									if (a != null) {
										if (a.equalsIgnoreCase(action)) {
											return true;
										}
									}
								}
							}
						}
					}
				}
				return false;
			}

		};
		return getAllRS2Objects(filter);

	}




}

Edited by TheScrub

public RS2Object[] getObjectsWithAction(final String action) {

        Filter<RS2Object> filter = new Filter<RS2Object>() {

            @Override

            public boolean accept(RS2Object t) {

                if (t != null) {

                    if (t.getDefinition() != null) {

                        if (t.getDefinition().getActions() != null) {

                            if (t.getDefinition().getActions().length > 0) {

                                for (String a : t.getDefinition().getActions()) {

                                    if (a != null) {

                                        if (a.equalsIgnoreCase(action)) {

                                            return true;

                                        }

                                    }

                                }

                            }

                        }

                    }

                }

                return false;

            }

        };

        return getAllRS2Objects(filter);

    }

Nesting if-statments much?

You could just create a generic method.

public <T> T filter(final T[] types, final Filter<T> filter) {
        for(final T type : types) {
            if(filter.accept(type)) {
                return type;
            }
        }
        return null;
    }

Edited by Parameter

  • Author

 

You could just create a generic method.

public <T> T filter(final T[] types, final Filter<T> filter) {
        for(final T type : types) {
            if(filter.accept(type)) {
                return type;
            }
        }
        return null;
    }

 

ahh i like this

 

You could just create a generic method.

public <T> T filter(final T[] types, final Filter<T> filter) {
        for(final T type : types) {
            if(filter.accept(type)) {
                return type;
            }
        }
        return null;
    }

Generics will make it somewhat slower, but it's fine since it's unnoticeable.

Guest
This topic is now closed to further replies.

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.