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

(Snippet) [Entitype] How to collect a list of any Entity sub-class type

Featured Replies

Allows you to group multiple entity types in one list which may or may not allow for more efficient overall traversal cost / filtering.

 

Allows you to access sub-list of RS2Object sub-types such as Wall Decoration, which may allow for more efficient filtering.

 

Examples:

List<Entity> wallRelated = Entitype.collect(this, Entitype.OBJECT_WALL_DECORATION, Entitype.OBJECT_WALL_OBJECT);

List<Entity> playersAndGroundItems = Entitype.collect(this, Entitype.PLAYER, Entitype.GROUND_ITEM);

List<Entity> all = Entitype.collect(this, Entitype.ALL);
		List<Entity> entities = Entitype.collect(ctx, Entitype.OBJECT_ALL, Entitype.NPC, Entitype.GROUND_ITEM);
		if(!entities.isEmpty()) {
			Entity target = entities.get(random.nextInt(entities.size()));
			target.examine();
		}

Snippet:

import java.util.ArrayList;
import java.util.List;
import java.util.stream.IntStream;

import org.osbot.rs07.api.model.Character;
import org.osbot.rs07.api.model.Entity;
import org.osbot.rs07.api.model.GroundDecoration;
import org.osbot.rs07.api.model.InteractableObject;
import org.osbot.rs07.api.model.RS2Object;
import org.osbot.rs07.api.model.WallDecoration;
import org.osbot.rs07.api.model.WallObject;
import org.osbot.rs07.script.MethodProvider;

public class Entitype {
	
	public static final int OBJECT_GROUND_DECORATION = 0;
	public static final int OBJECT_INTERACTABLE_OBJECT = 1;
	public static final int OBJECT_WALL_DECORATION = 2; 
	public static final int OBJECT_WALL_OBJECT = 3;
	public static final int OBJECT_ALL = 4;
	public static final int CHARACTER = 5;
	public static final int NPC = 6;
	public static final int PLAYER = 7;
	public static final int GROUND_ITEM = 8;
	public static final int ALL = 9;
	
	public static List<Entity> collect(MethodProvider ctx, int... types) {
		
		List<Entity> result = new ArrayList<>();
		
		List<Entity> objectsGroundDecoration = new ArrayList<>();
		List<Entity> objectsInteractableObject = new ArrayList<>();
		List<Entity> objectsWallDecoration = new ArrayList<>();
		List<Entity> objectsWallObject = new ArrayList<>();
		
		if(IntStream.of(types).anyMatch(x -> x < OBJECT_ALL)) {
			for (RS2Object o : ctx.getObjects().getAll()) {
				Class<?> clazz = o.getClass();
				if(clazz.equals(GroundDecoration.class)) {
					objectsGroundDecoration.add(o);
				}
				else if(clazz.equals(InteractableObject.class)) {
					objectsInteractableObject.add(o);
				}
				else if(clazz.equals(WallDecoration.class)) {
					objectsWallDecoration.add(o);
				}
				else if(clazz.equals(WallObject.class)) {
					objectsWallObject.add(o);
				}
			}
		}

		for (int type : types) {
			switch (type) {
			case ALL:
				List<Entity> all = new ArrayList<>();
				all.addAll(ctx.getObjects().getAll());
				all.addAll(ctx.getNpcs().getAll());
				all.addAll(ctx.getPlayers().getAll());
				result.addAll(all);
				break;
			case OBJECT_ALL:
				result.addAll(ctx.getObjects().getAll());
				break;
			case OBJECT_GROUND_DECORATION:
				result.addAll(objectsGroundDecoration);
				break;
			case OBJECT_INTERACTABLE_OBJECT:
				result.addAll(objectsInteractableObject);
				break;
			case OBJECT_WALL_DECORATION:
				result.addAll(objectsWallDecoration);
				break;
			case OBJECT_WALL_OBJECT:
				result.addAll(objectsWallObject);
				break;
			case CHARACTER:
				List<Character<?>> characters = new ArrayList<>();
				characters.addAll(ctx.getNpcs().getAll());
				characters.addAll(ctx.getPlayers().getAll());
				result.addAll(characters);
				break;
			case NPC:
				result.addAll(ctx.getNpcs().getAll());
				break;
			case PLAYER:
				result.addAll(ctx.getPlayers().getAll());
				break;
			case GROUND_ITEM:
				result.addAll(ctx.getGroundItems().getAll());
				break;
			}
			
		}
		return result;
	}
	
}

Edited by Botre

Create an account or sign in to comment

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Search

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.