Jump to content

Get the first option of a context menu?


Bobrocket

Recommended Posts

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
Link to comment
Share on other sites

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'

Link to comment
Share on other sites

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".

 

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

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
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...