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.

Show Item IDs In Inventory & Equipment Source Code

Featured Replies

This code will show all the item IDs in your inventory and equipment when you view that tab.

Imports & Overriding...

>>> Add imports:

import org.osbot.script.*;
import org.osbot.script.rs2.model.Item;
import org.osbot.script.rs2.ui.EquipmentSlot;
import org.osbot.script.rs2.ui.EquipmentTab;
import org.osbot.script.rs2.ui.Tab;

import java.awt.*;

 

>>> The override:
@Override
public void onPaint(Graphics g)
{

}

Step 1

 

In the onPaint method cast the current Graphics to 2D Graphics and call the method showItemIDs.

@Override
public void onPaint(Graphics g)
{
    Graphics2D g2 = (Graphics2D)g;
    showItemIDs(g2);
}

Step 2

 

Add the following methods...

public void showItemIDs(Graphics2D g2)
{
    Composite old = g2.getComposite();
    if(currentTab() == Tab.INVENTORY)
    {
        Item[] items = client.getInventory().getItems();
        for(int i = 0; i < items.length; i++)
        {
            if(currentTab() != Tab.INVENTORY)
                return;
            if(items[i] != null)
            {
                Rectangle r = client.getInventory().getDestinationForSlot(i);
                if(r != null)
                    drawItemData(g2, r, items[i].getId());
            }
        }
    }
    else if(currentTab() == Tab.EQUIPMENT)
    {
        for(Item item : equipmentTab.getItems())
        {
            if(currentTab() != Tab.EQUIPMENT)
                return;
            if(item != null)
            {
                Rectangle r = client.getInterface(387).getChild(equipmentTab.getSlotForId(item.getId()).childId).getRectangle();
                if(r != null)
                    drawItemData(g2, r, item.getId());
            }
        }
    }
    g2.setComposite(old);
}
private void drawItemData(Graphics2D g2, Rectangle r, int id)
{
    int nx = (int) r.getX(), ny = (int) r.getY(), h = g2.getFontMetrics().getHeight();
    String s = "" + id;
    g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.60f));
    g2.setColor(Color.WHITE);
    g2.fillRect(nx + (int) ((r.getWidth() - g2.getFontMetrics().stringWidth(s)) / 2) - 2, ny + h / 4, g2.getFontMetrics().stringWidth(s) + 4, h);
    g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1.00f));
    g2.setColor(Color.BLACK);
    g2.drawString(s, nx + (int) ((r.getWidth() - g2.getFontMetrics().stringWidth(s)) / 2), ny + h);
}

The Result...

post-501-0-64129400-1372948452_thumb.png

post-501-0-10762300-1372948455_thumb.png

Edited by TheAnswer

  • 4 weeks later...

Please don't take this the wrong way, but after studying your code, I've come up with a more efficient, easy-to-read method:

	@Override
	public void onPaint(Graphics arg0) {

		Graphics2D g = (Graphics2D) arg0;
		if (currentTab() == Tab.INVENTORY)
			drawInventory(g);
		else if (currentTab() == Tab.EQUIPMENT)
			drawEquipment(g);
	}
	
	public void drawInventory(Graphics2D arg0) {
		int i = 0;
		for (Item next : client.getInventory().getItems()) {
			if (next != null)
				drawString(arg0,
						String.valueOf(next.getId()),
						client.getInventory().getDestinationForSlot(i));
			i++;	
		}
	}
	
	public void drawEquipment(Graphics2D arg0) {
		for (Item next : equipmentTab.getItems())
			if (next != null)
				drawString(arg0,
						String.valueOf(next.getId()),
						client.getInterface(387).getChild(equipmentTab.getSlotForId(next.getId())
								.childId).getRectangle());
				
	}
	
	public void drawString(Graphics2D arg0, String arg1, Rectangle arg2) {
		if (arg0 == null || arg1 == null || arg1.length() == 0 || arg2 == null
				|| arg2.width <= 0 || arg2.height <= 0)
			return; // No point painting...
		
		FontMetrics fm = arg0.getFontMetrics();
		Point p = new Point(
				(int) (arg2.x + (arg2.width - fm.stringWidth(arg1)) / 2),
				(int) (arg2.y + (arg2.height - fm.getHeight())));
		arg0.setColor(Color.YELLOW);
		arg0.draw(arg2);
		arg0.setColor(Color.BLACK);
		arg0.drawString(arg1, p.x - 2, p.y - 2);
		arg0.drawString(arg1, p.x - 2, p.y + 2);
		arg0.drawString(arg1, p.x + 2, p.y - 2);
		arg0.drawString(arg1, p.x + 2, p.y + 2);
		arg0.setColor(Color.YELLOW);
		arg0.drawString(arg1, p.x, p.y);
	}

Edited by liverare

  • 2 weeks later...
  • Author

 

Please don't take this the wrong way, but after studying your code, I've come up with a more efficient, easy-to-read method:

	@Override
	public void onPaint(Graphics arg0) {

		Graphics2D g = (Graphics2D) arg0;
		if (currentTab() == Tab.INVENTORY)
			drawInventory(g);
		else if (currentTab() == Tab.EQUIPMENT)
			drawEquipment(g);
	}
	
	public void drawInventory(Graphics2D arg0) {
		int i = 0;
		for (Item next : client.getInventory().getItems()) {
			if (next != null)
				drawString(arg0,
						String.valueOf(next.getId()),
						client.getInventory().getDestinationForSlot(i));
			i++;	
		}
	}
	
	public void drawEquipment(Graphics2D arg0) {
		for (Item next : equipmentTab.getItems())
			if (next != null)
				drawString(arg0,
						String.valueOf(next.getId()),
						client.getInterface(387).getChild(equipmentTab.getSlotForId(next.getId())
								.childId).getRectangle());
				
	}
	
	public void drawString(Graphics2D arg0, String arg1, Rectangle arg2) {
		if (arg0 == null || arg1 == null || arg1.length() == 0 || arg2 == null
				|| arg2.width <= 0 || arg2.height <= 0)
			return; // No point painting...
		
		FontMetrics fm = arg0.getFontMetrics();
		Point p = new Point(
				(int) (arg2.x + (arg2.width - fm.stringWidth(arg1)) / 2),
				(int) (arg2.y + (arg2.height - fm.getHeight())));
		arg0.setColor(Color.YELLOW);
		arg0.draw(arg2);
		arg0.setColor(Color.BLACK);
		arg0.drawString(arg1, p.x - 2, p.y - 2);
		arg0.drawString(arg1, p.x - 2, p.y + 2);
		arg0.drawString(arg1, p.x + 2, p.y - 2);
		arg0.drawString(arg1, p.x + 2, p.y + 2);
		arg0.setColor(Color.YELLOW);
		arg0.drawString(arg1, p.x, p.y);
	}

Nice liverare. I was in my learning phase at the time but thanks for updating smile.png

Edited by TheAnswer

 

Please don't take this the wrong way, but after studying your code, I've come up with a more efficient, easy-to-read method:

	@Override
	public void onPaint(Graphics arg0) {

		Graphics2D g = (Graphics2D) arg0;
		if (currentTab() == Tab.INVENTORY)
			drawInventory(g);
		else if (currentTab() == Tab.EQUIPMENT)
			drawEquipment(g);
	}
	
	public void drawInventory(Graphics2D arg0) {
		int i = 0;
		for (Item next : client.getInventory().getItems()) {
			if (next != null)
				drawString(arg0,
						String.valueOf(next.getId()),
						client.getInventory().getDestinationForSlot(i));
			i++;	
		}
	}
	
	public void drawEquipment(Graphics2D arg0) {
		for (Item next : equipmentTab.getItems())
			if (next != null)
				drawString(arg0,
						String.valueOf(next.getId()),
						client.getInterface(387).getChild(equipmentTab.getSlotForId(next.getId())
								.childId).getRectangle());
				
	}
	
	public void drawString(Graphics2D arg0, String arg1, Rectangle arg2) {
		if (arg0 == null || arg1 == null || arg1.length() == 0 || arg2 == null
				|| arg2.width <= 0 || arg2.height <= 0)
			return; // No point painting...
		
		FontMetrics fm = arg0.getFontMetrics();
		Point p = new Point(
				(int) (arg2.x + (arg2.width - fm.stringWidth(arg1)) / 2),
				(int) (arg2.y + (arg2.height - fm.getHeight())));
		arg0.setColor(Color.YELLOW);
		arg0.draw(arg2);
		arg0.setColor(Color.BLACK);
		arg0.drawString(arg1, p.x - 2, p.y - 2);
		arg0.drawString(arg1, p.x - 2, p.y + 2);
		arg0.drawString(arg1, p.x + 2, p.y - 2);
		arg0.drawString(arg1, p.x + 2, p.y + 2);
		arg0.setColor(Color.YELLOW);
		arg0.drawString(arg1, p.x, p.y);
	}

you could name some of your vars better, also look into finalizing some things.

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.