lisabe96 Posted February 22, 2016 Posted February 22, 2016 How can I with the API determine what Position I'm hovering at. The same as when you use the entity debug option that shows which tile coordinates your hovering on. It's probably something simple but I haven't found anything useful in the API.
Extreme Scripts Posted February 22, 2016 Posted February 22, 2016 Entity hover debug shows you which tile you are hovering over if thats what you need. 1
lisabe96 Posted February 22, 2016 Author Posted February 22, 2016 (edited) Entity hover debug shows you which tile you are hovering over if thats what you need. That's exactly what I need but I need it in code. Maybe this example will be more clear: void mouseMoved(MouseEvent e) { Tile tile = new Tile(mouseX, mouseY); log(tile.getPosition()); } This obvious doesn't work, I'm after how I would get this working within osbot Edited February 22, 2016 by lisabe96
BloodRush20 Posted February 22, 2016 Posted February 22, 2016 That's exactly what I need but I need it in code. Maybe this example will be more clear: void mouseMoved(MouseEvent e) { Tile tile = new Tile(mouseX, mouseY); log(tile.getPosition()); } This obvious doesn't work, I'm after how I would get this working within osbot Not 100% since im not where I can freely test. The solution might be mouse().getArea(); As I said I recall doing this at one point in scripting but I'd have to test it.
Flamezzz Posted February 22, 2016 Posted February 22, 2016 Perhaps you can do something like: for each tile in myplayer.getArea(radius): if tile.polygon contains (mx, my): return tilenot the most efficient solution tho
lisabe96 Posted February 22, 2016 Author Posted February 22, 2016 Perhaps you can do something like: for each tile in myplayer.getArea(radius): if tile.polygon contains (mx, my): return tile not the most efficient solution tho I hope to find something more efficient, but I'll give it a try if I can't figure out anything else Not 100% since im not where I can freely test. The solution might be mouse().getArea(); As I said I recall doing this at one point in scripting but I'd have to test it. This would return java.awt.geom.Area
Explv Posted February 22, 2016 Posted February 22, 2016 http://osbot.org/forum/topic/66742-getting-position/
Flamezzz Posted February 22, 2016 Posted February 22, 2016 I hope to find something more efficient, but I'll give it a try if I can't figure out anything else This would return java.awt.geom.Area I briefly looked at org.osbot.core.debug.HoverDebug and I think it does the same thing, looping through every tile but it compares points in a polygon.
lisabe96 Posted February 22, 2016 Author Posted February 22, 2016 http://osbot.org/forum/topic/66742-getting-position/ Thanks! This should be enough information to get it working
lisabe96 Posted February 22, 2016 Author Posted February 22, 2016 Got it working It doesn't look good when the camera is tilted as it draws the screen and not the game world obviously. But it works. private List<Position> tiles = new ArrayList<>(); @Override public void mouseDragged(MouseEvent e) { handle(e); } @Override public void mouseClicked(MouseEvent e) { handle(e); } private void handle(MouseEvent e) { log(e.getX() + ", " + e.getY()); Position pos = getPosition(e.getPoint()); if (exists(pos)) { tiles.remove(pos); return; } tiles.add(pos); } @Override public void onPaint(Graphics2D graphics) { Graphics2D g = (Graphics2D) graphics; g.setRenderingHints(new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF)); g.setColor(Color.GREEN); if (!tiles.isEmpty()) { for (Position t : tiles) { if (t.isVisible(getBot())) { g.draw(t.getPolygon(getBot()).getBounds()); } } } } private Position getPosition(Point mousePosition) { for(int x = 0; x < 104; x++) { for(int y = 0; y < 104; y++) { Position pos = new Position(getMap().getBaseX()+x, getMap().getBaseY()+y, getMap().getPlane()); if(pos.isVisible(getBot()) && pos.getPolygon(getBot()).contains(mousePosition)) { return pos; } } } return null; } private boolean exists(Position pos) { if (!tiles.isEmpty()) { for (Position tile : tiles) { if (tile.equals(pos)) { return true; } } } return false; }
Explv Posted February 22, 2016 Posted February 22, 2016 Got it working It doesn't look good when the camera is tilted as it draws the screen and not the game world obviously. But it works. private List<Position> tiles = new ArrayList<>(); @Override public void mouseDragged(MouseEvent e) { handle(e); } @Override public void mouseClicked(MouseEvent e) { handle(e); } private void handle(MouseEvent e) { log(e.getX() + ", " + e.getY()); Position pos = getPosition(e.getPoint()); if (exists(pos)) { tiles.remove(pos); return; } tiles.add(pos); } @Override public void onPaint(Graphics2D graphics) { Graphics2D g = (Graphics2D) graphics; g.setRenderingHints(new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF)); g.setColor(Color.GREEN); if (!tiles.isEmpty()) { for (Position t : tiles) { if (t.isVisible(getBot())) { g.draw(t.getPolygon(getBot()).getBounds()); } } } } private Position getPosition(Point mousePosition) { for(int x = 0; x < 104; x++) { for(int y = 0; y < 104; y++) { Position pos = new Position(getMap().getBaseX()+x, getMap().getBaseY()+y, getMap().getPlane()); if(pos.isVisible(getBot()) && pos.getPolygon(getBot()).contains(mousePosition)) { return pos; } } } return null; } private boolean exists(Position pos) { if (!tiles.isEmpty()) { for (Position tile : tiles) { if (tile.equals(pos)) { return true; } } } return false; } Try doing this instead: g.drawPolygon(t.getPolygon(getBot())); 1
lisabe96 Posted February 22, 2016 Author Posted February 22, 2016 Try doing this instead: g.drawPolygon(t.getPolygon(getBot())); Exactly what I wanted! Thanks a bunch
Botre Posted February 23, 2016 Posted February 23, 2016 I'm not sure drawPolygon will work if the position's Z coordinate is not 0 (could be wrong). If this is the case you could use: Polygon p = position.getPolygon(getBot(), myPosition().getZ()); if(p != null) g2d.draw(p); Which I can confirm DOES work on with all planes. Cheers 1
lisabe96 Posted February 23, 2016 Author Posted February 23, 2016 I'm not sure drawPolygon will work if the position's Z coordinate is not 0 (could be wrong). If this is the case you could use: Polygon p = position.getPolygon(getBot(), myPosition().getZ()); if(p != null) g2d.draw(p); Which I can confirm DOES work on with all planes. Cheers Thanks, will use. Better avoid possible problems