PshYouLost Posted July 24, 2017 Share Posted July 24, 2017 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! Quote Link to comment Share on other sites More sharing options...
progamerz Posted July 24, 2017 Share Posted July 24, 2017 (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 July 24, 2017 by progamerz 1 Quote Link to comment Share on other sites More sharing options...
PshYouLost Posted July 24, 2017 Author Share Posted July 24, 2017 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? Quote Link to comment Share on other sites More sharing options...
progamerz Posted July 24, 2017 Share Posted July 24, 2017 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 Quote Link to comment Share on other sites More sharing options...
Apaec Posted July 24, 2017 Share Posted July 24, 2017 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?) 1 Quote Link to comment Share on other sites More sharing options...
Tom Posted July 24, 2017 Share Posted July 24, 2017 (edited) 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-- Edited July 24, 2017 by Tom Quote Link to comment Share on other sites More sharing options...
PshYouLost Posted July 24, 2017 Author Share Posted July 24, 2017 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. Quote Link to comment Share on other sites More sharing options...
Tom Posted July 24, 2017 Share Posted July 24, 2017 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 Quote Link to comment Share on other sites More sharing options...
PshYouLost Posted July 24, 2017 Author Share Posted July 24, 2017 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? Quote Link to comment Share on other sites More sharing options...
Tom Posted July 24, 2017 Share Posted July 24, 2017 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 Quote Link to comment Share on other sites More sharing options...
PshYouLost Posted July 24, 2017 Author Share Posted July 24, 2017 (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 July 24, 2017 by PshYouLost 3 Quote Link to comment Share on other sites More sharing options...