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 convert mouse coordinate to RS position

Featured Replies

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.

  • Author

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 by lisabe96

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.

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

  • Author

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

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.

  • Author

Got it working :D

It doesn't look good when the camera is tilted as it draws the screen and not the game world obviously.

But it works.

 

MQ0IhH1.png

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;
}

 

Got it working biggrin.png

It doesn't look good when the camera is tilted as it draws the screen and not the game world obviously.

But it works.

 

MQ0IhH1.png

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()));
  • Author

 

Try doing this instead:

g.drawPolygon(t.getPolygon(getBot()));

Exactly what I wanted! Thanks a bunch

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

  • Author

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 :)

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.