Jump to content

How to get click area for context menu


colby__

Recommended Posts

I am writing an alternate mouse movement/clicking method. How can I get the bounding box for a context option? For example, if I right click on a chest, how would I get the on screen coordinates of the "Open" option so that I can use a Robot to move the mouse to that position? thanks!
 

public java.awt.Rectangle getOptionRectangle(int index)

Is that what will give me the bounding box for the "Open" option? It's named different from every other bounding box lol

 

Also, I notice that this method that lets me select a specific entity is deprecated. Why? How do i select a specific object to open?

@Deprecated
public int getMenuIndex(Entity entity,
java.lang.String[] actions,
java.lang.String[] names)

Link to comment
Share on other sites

I am writing an alternate mouse movement/clicking method. How can I get the bounding box for a context option? For example, if I right click on a chest, how would I get the on screen coordinates of the "Open" option so that I can use a Robot to move the mouse to that position? thanks!

 

public java.awt.Rectangle getOptionRectangle(int index)

Is that what will give me the bounding box for the "Open" option? It's named different from every other bounding box lol

 

Also, I notice that this method that lets me select a specific entity is deprecated. Why? How do i select a specific object to open?

@Deprecated

public int getMenuIndex(Entity entity,

java.lang.String[] actions,

java.lang.String[] names)

 

getOptionRectangle gives you the bounding box for the menu item at the provided index.

The noun and vars of the option can help you determine which entity (if any) has the action

 

Link to comment
Share on other sites

I am writing an alternate mouse movement/clicking method.

 

i heard earlier on this forum that jagex cant, or just straight up doesnt, track your specific mouse movements. given that, i'm not sure how this project is going to help you or what the end goal of this is, but gl

Edited by Imateamcape
Link to comment
Share on other sites

public boolean selectAction(String action) {
	return mouse.click(new RectangleDestination(bot, menu.getOptionRectangle(menu.getMenu()
			.indexOf(menu.getMenu().stream().filter(o -> o.action.equals(action)).findFirst().get()))));
}

Don't forget to take into account some menus include color tags

Link to comment
Share on other sites

public boolean selectAction(String action) {
	return mouse.click(new RectangleDestination(bot, menu.getOptionRectangle(menu.getMenu()
			.indexOf(menu.getMenu().stream().filter(o -> o.action.equals(action)).findFirst().get()))));
}

Don't forget to take into account some menus include color tags

 

 

you're using optionals incorrectly l

 

  • Like 1
Link to comment
Share on other sites

getOptionRectangle gives you the bounding box for the menu item at the provided index.

The noun and vars of the option can help you determine which entity (if any) has the action

 

 

 

public boolean selectAction(String action) {
	return mouse.click(new RectangleDestination(bot, menu.getOptionRectangle(menu.getMenu()
			.indexOf(menu.getMenu().stream().filter(o -> o.action.equals(action)).findFirst().get()))));
}

Don't forget to take into account some menus include color tags

 

 

 

you're using optionals incorrectly l

 

 

Thanks guys! So how do I do this for at an object at a particular X, Y since there are multiple chests with the same Id and options in the same area?

 

i heard earlier on this forum that jagex cant, or just straight up doesnt, track your specific mouse movements. given that, i'm not sure how this project is going to help you or what the end goal of this is, but gl

What if my goal is to remove mouse movements?

Link to comment
Share on other sites

Thanks guys! So how do I do this for at an object at a particular X, Y since there are multiple chests with the same Id and options in the same area?

 

What if my goal is to remove mouse movements?

 

I believe the vars contain data to uniquely identify NPCs and objects (Position / Character index)

By vars I mean the 3 'var' fields in the Options class (var1, var2, var3)

 

Edited by FrostBug
Link to comment
Share on other sites

I believe the vars contain data to uniquely identify NPCs and objects (Position / Character index)

By vars I mean the 3 'var' fields in the Options class (var1, var2, var3)

 

Can you elaborate? For example I would already have a reference to the RS2Object that I want to use the Open option on, so searching for it again seems like an inefficient way to do it, no? So say I have the RS2Object, I already right clicked on the object, what would be the code to get the bounding box for the option of the chest I already have a reference to? Thanks!

Link to comment
Share on other sites

Can you elaborate? For example I would already have a reference to the RS2Object that I want to use the Open option on, so searching for it again seems like an inefficient way to do it, no? So say I have the RS2Object, I already right clicked on the object, what would be the code to get the bounding box for the option of the chest I already have a reference to? Thanks!

 

Each option has 3 'vars' containing information about the entity in question. I dont actually know what these vars contain for RS2Objects, but for NPCs they contain the NPCs world index (and some other things), which can be used to verify that this is the correct option, given you have a reference to the NPC. Something similar should be doable with objects. Maybe one of the vars contains coordinates?

 

I'd suggest you go ingame with a script that prints the vars for each option, in order to see what's in there exactly

 

Link to comment
Share on other sites

I recall having posted a similar solution for this on an old thread. I'll re-post is here:

If there's a problem reading from widgets for actions, why not just circumvent actions altogether? If you know of instances where you're only left clicking, just do that. But if you're required to right click to find an action, just find the index the action's at, calculate its bounds and return true if bot clicks within the action index bounds:
 

test_zps3pf3zv4l.png

(Tested 6 indexes in standard mode)

 

testm_zps9qsasu9o.png

(Tested 10 indexes in Mirror Mode)

 
Code:

public RectangleDestination getMenuBounds(int index) {
		
		final int offx = 2;
		final int offy = 19;
		final int offw = 5;
		
		final int menuItemHeight = 15;
		
		RectangleDestination rd = null;
		
		Rectangle r = null;
		
		if (index < 0) {
			throw new IllegalArgumentException("Index number must be positive!");
		} else if (getMenuAPI().isOpen()) {
			r = new Rectangle();
			r.x = getMenuAPI().getX() + offx;
			r.y = (getMenuAPI().getY() + offy) + (index * menuItemHeight);
			r.width = getMenuAPI().getWidth() - offw;
			r.height = menuItemHeight;

			/*
			 * Final off-setting to ensure the menu item's Y and height sit
			 * accurately on the interaction
			 */
			r.y++;
			r.height -= 2;
			
			rd = new RectangleDestination(bot, r);
		}
		return rd;
	} 


 
Example of usage:

	...
	
	RectangleDestination rd = getMenuBounds(3); // "Make X"
	if (rd != null && getMouse().click(rd)) {
		// Do something
	} else {
		// Do something else
	}
	
	... 


 
Scruffy example of interaction based on client mode:

public void interact(RS2Widget widget, String action) {

		if (getClient().isMirrorMode()) {
			// Execute alternative solution

			if (getMouse().click(new WidgetDestination(bot, widget), true)) {
				// Right clicked the widget we want to interact with

				RectangleDestination rd = getMenuBounds(3);

				if (rd != null && getMouse().click(rd)) {
					// index 3 = 'Make X'
					
					// Do something...
					
				} else {
					
					// Do something else...
				}
			} else {
				// Move mouse using RectangleDestination
				// Note: very bad for resize mode
			}

		} else {
			// Execute regular solution
			if (widget.interact(action)) {
				
				// Do something...
				
			} else {
				
				// Do something else...
			}
		}
	} 

 

This isn't exactly what you're after, but it should be useful nonetheless.

Edited by liverare
Link to comment
Share on other sites

Each option has 3 'vars' containing information about the entity in question. I dont actually know what these vars contain for RS2Objects, but for NPCs they contain the NPCs world index (and some other things), which can be used to verify that this is the correct option, given you have a reference to the NPC. Something similar should be doable with objects. Maybe one of the vars contains coordinates?

 

I'd suggest you go ingame with a script that prints the vars for each option, in order to see what's in there exactly

 

Well see why I am asking is because the 

 

I recall having posted a similar solution for this on an old thread. I'll re-post is here:

If there's a problem reading from widgets for actions, why not just circumvent actions altogether? If you know of instances where you're only left clicking, just do that. But if you're required to right click to find an action, just find the index the action's at, calculate its bounds and return true if bot clicks within the action index bounds:

 

test_zps3pf3zv4l.png

(Tested 6 indexes in standard mode)

 

testm_zps9qsasu9o.png

(Tested 10 indexes in Mirror Mode)

 

Code:

public RectangleDestination getMenuBounds(int index) {
		
		final int offx = 2;
		final int offy = 19;
		final int offw = 5;
		
		final int menuItemHeight = 15;
		
		RectangleDestination rd = null;
		
		Rectangle r = null;
		
		if (index < 0) {
			throw new IllegalArgumentException("Index number must be positive!");
		} else if (getMenuAPI().isOpen()) {
			r = new Rectangle();
			r.x = getMenuAPI().getX() + offx;
			r.y = (getMenuAPI().getY() + offy) + (index * menuItemHeight);
			r.width = getMenuAPI().getWidth() - offw;
			r.height = menuItemHeight;

			/*
			 * Final off-setting to ensure the menu item's Y and height sit
			 * accurately on the interaction
			 */
			r.y++;
			r.height -= 2;
			
			rd = new RectangleDestination(bot, r);
		}
		return rd;
	} 

 

Example of usage:

	...
	
	RectangleDestination rd = getMenuBounds(3); // "Make X"
	if (rd != null && getMouse().click(rd)) {
		// Do something
	} else {
		// Do something else
	}
	
	... 

 

Scruffy example of interaction based on client mode:

public void interact(RS2Widget widget, String action) {

		if (getClient().isMirrorMode()) {
			// Execute alternative solution

			if (getMouse().click(new WidgetDestination(bot, widget), true)) {
				// Right clicked the widget we want to interact with

				RectangleDestination rd = getMenuBounds(3);

				if (rd != null && getMouse().click(rd)) {
					// index 3 = 'Make X'
					
					// Do something...
					
				} else {
					
					// Do something else...
				}
			} else {
				// Move mouse using RectangleDestination
				// Note: very bad for resize mode
			}

		} else {
			// Execute regular solution
			if (widget.interact(action)) {
				
				// Do something...
				
			} else {
				
				// Do something else...
			}
		}
	} 

 

This isn't exactly what you're after, but it should be useful nonetheless.

That works in theory however if some payer stands where I am right clicking, it will change where the Open index is in the menu, no? How would I know what to pass for "getMenuBounds(int index)" index if it is changing based on the amount of players standing around the object?

Do you know how to make the above method work with functionality like the following code below 

public int getMenuIndex(Entity entity,

java.lang.String[] actions,

java.lang.String[] names)

Where I can select a specific action on a specific entity? 

Link to comment
Share on other sites

Well see why I am asking is because the 

 

That works in theory however if some payer stands where I am right clicking, it will change where the Open index is in the menu, no? How would I know what to pass for "getMenuBounds(int index)" index if it is changing based on the amount of players standing around the object?

Do you know how to make the above method work with functionality like the following code below 

public int getMenuIndex(Entity entity,

java.lang.String[] actions,

java.lang.String[] names)

Where I can select a specific action on a specific entity? 

 

Using the vars like I suggested

For example what I did with NPCs to solve this problem (pseudo):

 

NPC npc = getNPC();

String action = "Talk-to";

foreach(Option option in options) {

    if(action.equals(option.action) && npc.getIndex() == option.var1) {

        //This is the correct option!

    }

}

 

Which is possible because var1 contains the entity world index. The vars contain similar unique information for RS2Objects, you just have to debug it a little to find out what.

Edited by FrostBug
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...