Jump to content

Get the first option of a context menu?


Recommended Posts

Posted (edited)

Try using widgets. Otherwise you could open menu and use menu.getMenu(). You'll get all menu options stored in a list. Thereafter you could loop through the list and find the menu action you are looking for.

 

EDIT: You could also use EntityDefinition

RS2Object stall = objects.closest("Silk stall");

String[] actions = stall.getDefinition().getActions();
Edited by Woody
Posted

object.getActions()[0] for the first option in the index*

 

careful though, some objects have null options, so you may want to make a small method to filter out all the null options

 

e.g. I tried doing this for my bank method, (bank chests have 'use', bank booths have 'bank') however the bank booth's first hidden option was null, then it was 'Bank'

Posted

object.getActions()[0] for the first option in the index*

 

careful though, some objects have null options, so you may want to make a small method to filter out all the null options

 

e.g. I tried doing this for my bank method, (bank chests have 'use', bank booths have 'bank') however the bank booth's first hidden option was null, then it was 'Bank'

Thank you :)

Will this still work if there are things in the way? For example, if there is a guard in the way the first option would be "Pickpocket" for the guard, but the first option for the stall is always "Steal-from".

 

Posted

Thank you smile.png

Will this still work if there are things in the way? For example, if there is a guard in the way the first option would be "Pickpocket" for the guard, but the first option for the stall is always "Steal-from".

 

 

yes it will, it only grabs the options for that specific object

Posted

yes it will, it only grabs the options for that specific object

I fixed it a different way:

if (getMouse().getOnCursorCount() > 1) {
	if (lock == 0) stall.interact("Steal-from");
	else log("Locked!!");
}
else {
	if (lock == 0) getMouse().click(false);
	else log("Locked!!");
}

Seems to work better for me. No idea why :/

 

Another problem I'm having: both localWalker and getMap() refuse to move my character one square to the left..

while (!getMap().walk(p)) { }
log("trying to walk " + myPlayer().getPosition() + " " + p);

It will log, so it shows that the while loop ends (indicating that the walk has executed) although the mouse doesn't move and the neither does the player; it's stuck there forever.

 

Posted (edited)

Not sure if still relevant, but a way to get the general uptext is:

	/*
	 * Get the mouse uptext
	 */
	public String getUpText() {
		List<Option> menu = getMenuAPI().getMenu();
		if (menu != null && !menu.isEmpty()) {
			return menu.get(0).action;
		}
		return "Cancel";
	}

Despite the nature of the code, it does not require you to have a right-click menu open.

Edited by FrostBug

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

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