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.

How to get coordinates of Object?

Featured Replies

I'm currently trying to figure out how I can go about getting the X and Y coordinate of an item.

For example, let's say I want to get the X and Y coordinate of the nearest "Rock"

The code I have to so far would be

xCoord = getObjects().closest("Rocks").getX();
yCoord = getObjects().closest("Rocks").getY();

And just to test it out to see if I actually got the correct X and Y coordinate I run

mouse.move(xCoord, yCoord);

But the mouse ends up moving to some random place. Even if I walk around the game and get closer to a different Rock.

The end goal is for me to get the top-left X,Y coordinates and the bottom-right X,Y coordinates of all the Iron Rocks on the screen. So if you have a better way of figuring this out, I'd appreciate it!

 

Thanks!

9 minutes ago, PshYouLost said:

I'm currently trying to figure out how I can go about getting the X and Y coordinate of an item.

For example, let's say I want to get the X and Y coordinate of the nearest "Rock"

The code I have to so far would be


xCoord = getObjects().closest("Rocks").getX();
yCoord = getObjects().closest("Rocks").getY();

And just to test it out to see if I actually got the correct X and Y coordinate I run


mouse.move(xCoord, yCoord);

But the mouse ends up moving to some random place. Even if I walk around the game and get closer to a different Rock.

The end goal is for me to get the top-left X,Y coordinates and the bottom-right X,Y coordinates of all the Iron Rocks on the screen. So if you have a better way of figuring this out, I'd appreciate it!

 

Thanks!

getX() and getY() returns the tile  they are on not the screen position.

Edit: tho why u want to get their x,y for the screen?

Edited by progamerz

  • Author
1 minute ago, progamerz said:

getX() and getY() returns the tile  they are on not the screen position

Oh oops! What can I use to get their actual coordinates? Or

Is there a way to just get the top-left and bottom-right coordinates of an Object?

2 minutes ago, PshYouLost said:

Oh oops! What can I use to get their actual coordinates? Or

Is there a way to just get the top-left and bottom-right coordinates of an Object?

I don't think so u will have to do maybe some math and make a method for it, maybe try object.hover()? as i am not sure why u want to do that exactly

As a side note, calling getObjects#closest is not guarenteed to get the same 'rock' each time if you call it multiple times in succession! (what if the rock is mined between calls?)

  • Author
5 hours ago, progamerz said:

I don't think so u will have to do maybe some math and make a method for it, maybe try object.hover()? as i am not sure why u want to do that exactly

I don't actually care about moving my mouse to the object. I just did that so I can see what coordinate was actually picked up.

 

4 hours ago, Apaec said:

As a side note, calling getObjects#closest is not guarenteed to get the same 'rock' each time if you call it multiple times in succession! (what if the rock is mined between calls?)

Yeah I figured. I just wanted to test it out real quick.

So is there no way of actually get the coordinates of an object on screen?

50 minutes ago, Tom said:

Just use .hover() if you want to move your mouse over the rock

 

https://osbot.org/api/org/osbot/rs07/api/model/Interactable.html#hover--

I don't actually care about moving my mouse to the object. I just did that so I can see what coordinate was actually picked up.

41 minutes ago, PshYouLost said:

I don't actually care about moving my mouse to the object. I just did that so I can see what coordinate was actually picked up.

 

Yeah I figured. I just wanted to test it out real quick.

So is there no way of actually get the coordinates of an object on screen?

I don't actually care about moving my mouse to the object. I just did that so I can see what coordinate was actually picked up.

Oh sorry, I didn't read the OP past that point, my bad.

As for your solution, I can't really think of anything that wouldn't be extremely processing intensive, though there is probably some functionality in the API that can do what you need

  • Author
1 minute ago, Tom said:

Oh sorry, I didn't read the OP past that point, my bad.

As for your solution, I can't really think of anything that wouldn't be extremely processing intensive, though there is probably some functionality in the API that can do what you need

I honestly don't mind if it's extremely intensive lol :P

 

I was able to use this  to get the coordinates of the first inventory slot.

 

Rectangle inv = InventorySlotDestination.getSlot(inventory.getSlot("Iron ore"));
int xCoord = (int) inv.getX();
int yCoord = (int) inv.getY();

 But is there a way to get the coordinates of the rest of the items in the inventory?

18 minutes ago, PshYouLost said:

I honestly don't mind if it's extremely intensive lol :P

 

I was able to use this  to get the coordinates of the first inventory slot.

 


Rectangle inv = InventorySlotDestination.getSlot(inventory.getSlot("Iron ore"));
int xCoord = (int) inv.getX();
int yCoord = (int) inv.getY();

 But is there a way to get the coordinates of the rest of the items in the inventory?

What exactly do you need the top left and bottom right iron ores for?
If you're planning to draw over them or something I could probably write something up that would work

  • Author
28 minutes ago, Tom said:

What exactly do you need the top left and bottom right iron ores for?
If you're planning to draw over them or something I could probably write something up that would work

I'm actually just using osbot to help me with another project I need. The goal is to be able to take a screenshot of the RS screen and log the rectangle coords of all iron rocks. But I actually figured it out!

        List<RS2Object> rocks = objects.filter(t -> t != null && t.getName().equals("Rocks"));
        for (RS2Object rock : rocks) {
            int x = (int) rock.getModel().getBoundingBox(rock.getGridX(), rock.getGridY(), rock.getZ()).getX();
            int y = (int) rock.getModel().getBoundingBox(rock.getGridX(), rock.getGridY(), rock.getZ()).getY();
            log("x:" + x + " y:" + y);
//            mouse.move(x, y);
            sleep(2000);
        }

 

Edited by PshYouLost

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.