Jump to content

How to get coordinates of Object?


Recommended Posts

Posted

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!

Posted (edited)
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
  • Like 1
Posted
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.

Posted
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

Posted
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?

Posted
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

Posted (edited)
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
  • Like 3

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...