Jump to content

How to get coordinates of Object?


PshYouLost

Recommended Posts

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!

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

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