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.

Detect Worn Items of Other Players

Featured Replies

Hello.

I'm trying to write a fully functional cwars script, and have it actually defend the flag and run after players. I need it to read all the equipped items of nearby players into a list and iterate through until it finds the one holding the flag, it then needs to grab what gear they are wearing to attack using the combat triangle. 

I'm not quite sure how to read the gear of other players, because it's different than reading your own gear. I spent a lot of time reading the API, but can't find any way of possibly doing this. I was wondering if this is something that can be done with OSbots API and if anyone has any examples/hints of how to do this.

 

What I'm trying to do is something like this, however this code is invalid and halts execution of the client..

for(final Player player : getPlayers().getAll()) {
	if(player.getMethods().getEquipment().getItemInSlot(EquipmentSlot.WEAPON.slot).getName().contains("flag")) {
		//interact and attack player
	}
}

 

Edited by Kawaii_s

I wrote an API for this.
 

There's 5 functions of interest:

//AppearanceAPI.isDefined(Player, Predicare<ItemDefinition>)
//appearance.findPlayersWielding(Predicare<ItemDefinition>)
//appearance.findPlayersWielding(List<Player>, Predicare<ItemDefinition>)
//appearance.findPlayerWielding(Predicare<ItemDefinition>)
//appearance.findPlayerWielding(List<Player>, Predicare<ItemDefinition>)

Example:

Player randomPlayer123 = null; // TODO fix
		
if (AppearanceAPI.isDefined(randomPlayer123, id -> id.getName().equals("Dragon claws"))) {
	// TODO stuff...
}
List<Player> richPeople = appearance.findPlayersWielding(id -> id.getName().endsWith("spirit shield"));
		
for (Player richPerson : richPeople) {
	// TODO stuff....
}

Source:

package com.liverare.api;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Predicate;

import org.osbot.rs07.api.def.ItemDefinition;
import org.osbot.rs07.api.model.Player;
import org.osbot.rs07.script.API;

/**
 * Appearance API
 * 
 * @author LiveRare
 *
 */
public class AppearanceAPI extends API {

	@Override
	public void initializeModule() {
	}

	/**
	 * Find players wielding specific items
	 * 
	 * Note: rings are not retrieved
	 * 
	 * @param players
	 *            - Players to filter
	 * @param itemDefinitionFilter
	 *            - Filter
	 * @return List of filtered players
	 * @see {@link AppearanceAPI#isDefined(Player, Predicate)}
	 */
	public List<Player> findPlayersWielding(List<Player> players, Predicate<ItemDefinition> itemDefinitionFilter) {
		
		List<Player> results = null;

		if (players != null && !players.isEmpty() && itemDefinitionFilter != null) {

			results = new ArrayList<>();
			
			for (Player player : players) {
				
				if (isDefined(player, itemDefinitionFilter)) {
					
					results.add(player);
				}
			}
		}
		
		return results;
	}
	
	/**
	 * Find players wielding specific items
	 * 
	 * Note: rings are not retrieved
	 * 
	 * @param itemDefinitionFilter
	 *            - Filter
	 * @return List of filtered players
	 * @see {@link AppearanceAPI#findPlayersWielding(List, Predicate)}
	 */
	public List<Player> findPlayersWielding(Predicate<ItemDefinition> itemDefinitionFilter) {
		return findPlayersWielding(players.getAll(), itemDefinitionFilter);
	}
	
	/**
	 * Find first player wielding specific items
	 * 
	 * Note: rings are not retrieved
	 * 
	 * @param players
	 *            - Players to filter
	 * @param itemDefinitionFilter
	 *            - Filter
	 * @return List of filtered players
	 * @see {@link AppearanceAPI#findPlayersWielding(List, Predicate)}
	 */
	public Player findPlayerWielding(List<Player> players, Predicate<ItemDefinition> itemDefinitionFilter) {
		
		Player result = null;
		List<Player> filtered = findPlayersWielding(players, itemDefinitionFilter);
		
		if (filtered != null && !filtered.isEmpty()) {
			
			result = filtered.get(0);
		}
		
		return result;
	}
	
	/**
	 * Find first player wielding specific items
	 * 
	 * Note: rings are not retrieved
	 * 
	 * @param itemDefinitionFilter
	 *            - Filter
	 * @return List of filtered players
	 * @see {@link AppearanceAPI#findPlayerWielding(List, Predicate)}
	 */
	public Player findPlayerWielding(Predicate<ItemDefinition> itemDefinitionFilter) {
		return findPlayerWielding(players.getAll(), itemDefinitionFilter);
	}

	/**
	 * Test whether player is wielding a particular item
	 * 
	 * @param player
	 *            - Player
	 * @param itemDefinitionFilter
	 *            - Item filter
	 * @return <tt>Item found on player</tt>
	 * @see {@link AppearanceAPI#isDefined(int[], Predicate)}
	 */
	public static boolean isDefined(Player player, Predicate<ItemDefinition> itemDefinitionFilter) {
		return isDefined(player.getDefinition().getAppearance(), itemDefinitionFilter);
	}

	/**
	 * Gets item definitions for the items IDs in 'appearance' and tests them
	 * against the ItemDefinition filter
	 * 
	 * @param appearance
	 *            - Item IDs
	 * @param itemDefinitionFilter
	 *            - Filter
	 * @return <tt>Item found</tt>
	 */
	private static boolean isDefined(int[] appearance, Predicate<ItemDefinition> itemDefinitionFilter) {
		
		boolean result = false;
		ItemDefinition itemDefinition = null;
		
		if (appearance != null && appearance.length > 0) {
			
			for (int itemId : appearance) {
				
				if (itemId > 0) {
					
					itemId -= 512;
					
					itemDefinition = ItemDefinition.forId(itemId);
					
					if (itemDefinition != null && itemDefinitionFilter.test(itemDefinition)) {
						
						result = true;
						break;
					}
				}
			}
			
		}
		
		return result;
	}
	
}

Note: this is a custom API, so the gain access to all the methods that start with "appearance", you will have to instantiate a new AppearanceAPI object and exchange the bot's context with it (like so):

	AppearanceAPI appearance;
	
	@Override
	public void onStart() throws InterruptedException {
		appearance = new AppearanceAPI();
		appearance.exchangeContext(bot);
	}

Enjoy.

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.