Toph Posted December 19, 2013 Share Posted December 19, 2013 (edited) For some reason, OSBot doesn't have this already. So here: public boolean selectMenuOption(String action, String noun) throws InterruptedException { if (!client.isMenuOpen()) return false; boolean found = false; int index = 0; List<Option> menu = client.getMenu(); for (; index < menu.size(); index++) { if (menu.get(index).action.equals(action) && menu.get(index).noun.contains(noun)) { found = true; break; } } if (found) { int x = client.getMenuX(); int y = client.getMenuY() + 21 + index * 14; return client.moveMouseTo(new RectangleDestination(x, y, client.getMenuWidth(), 10), false, true, false); } return found; } Clicks a menu option from a currently visible menu. Edited December 19, 2013 by Toph 3 Link to comment Share on other sites More sharing options...
TzTok Jad Posted December 19, 2013 Share Posted December 19, 2013 For some reason, OSBot doesn't have this already. So here: public boolean selectMenuOption(String action, String noun) throws InterruptedException { if (!client.isMenuOpen()) return false; boolean found = false; int index = 0; List<Option> menu = client.getMenu(); for (; index < menu.size(); index++) { if (menu.get(index).action.equals(action) && menu.get(index).noun.contains(noun)) { found = true; break; } } if (found) { int x = client.getMenuX(); int y = client.getMenuY() + 21 + index * 14; return client.moveMouseTo(new RectangleDestination(x, y, client.getMenuWidth(), 10), false, true, false); } return found; } Clicks a menu option from a currently visible menu. Thank you so much, Link to comment Share on other sites More sharing options...
Acerd Posted December 21, 2013 Share Posted December 21, 2013 Interesting , will help alot of people thanks! Link to comment Share on other sites More sharing options...
TheScrub Posted December 21, 2013 Share Posted December 21, 2013 (edited) For some reason, OSBot doesn't have this already. So here: public boolean selectMenuOption(String action, String noun) throws InterruptedException { if (!client.isMenuOpen()) return false; boolean found = false; int index = 0; List<Option> menu = client.getMenu(); for (; index < menu.size(); index++) { if (menu.get(index).action.equals(action) && menu.get(index).noun.contains(noun)) { found = true; break; } } if (found) { int x = client.getMenuX(); int y = client.getMenuY() + 21 + index * 14; return client.moveMouseTo(new RectangleDestination(x, y, client.getMenuWidth(), 10), false, true, false); } return found; } Clicks a menu option from a currently visible menu. yer it's menu api is pretty bad compared to other clients for example a small client that I'm on has 1 Dev and has like 3 scriptwriter's and 10 users has a better MENU API than osbot lol but the rest of there API is behind Good contribution to site! Edited December 21, 2013 by TheScrub 1 Link to comment Share on other sites More sharing options...
Deffiliate Posted December 21, 2013 Share Posted December 21, 2013 Thank you so much Toph! Link to comment Share on other sites More sharing options...
Celeos Posted December 21, 2013 Share Posted December 21, 2013 Nice. Could be less messy though. Link to comment Share on other sites More sharing options...
lolmanden Posted December 21, 2013 Share Posted December 21, 2013 Thanks for this mate! Much apperciated. Link to comment Share on other sites More sharing options...
Toph Posted December 21, 2013 Author Share Posted December 21, 2013 Nice. Could be less messy though.Feel free to change it and I'll update the main post with credit given Link to comment Share on other sites More sharing options...
FrostBug Posted December 31, 2013 Share Posted December 31, 2013 (edited) Ah.. Should have checked the Snippets section yesterday when I needed this; Anyway, I've made a similar implementation; I suppose people can choose what fits their needs import java.util.ArrayList; import java.util.List; import org.osbot.script.mouse.RectangleDestination; import org.osbot.script.rs2.Client; import org.osbot.script.rs2.ui.Option; /** * * @author FrostBug */ public class Menu { private List<Option> options; private List<String> strOptions; private int x, y, width; private Client client; private static final int OPTION_HEIGHT = 15; private static final int TOP_PADDING = 19; private Menu(Client client) { this.strOptions = new ArrayList<>(); this.options = client.getMenu(); this.x = client.getMenuX(); this.y = client.getMenuY(); this.width = client.getMenuWidth(); this.client = client; for (Option o : options) { strOptions.add(o.action); } } public static Menu getActiveMenu(Client client) { if (client.isMenuOpen()) { return new Menu(client); } else { return null; } } public boolean hasOption(String action) { return strOptions.contains(action); } private RectangleDestination getDestinationRect(int index) { return new RectangleDestination(x + 4, y + TOP_PADDING + (index * OPTION_HEIGHT), width - 8, OPTION_HEIGHT); } public boolean moveMouseToOption(String action, boolean click) throws InterruptedException { int index = strOptions.indexOf(action); boolean success; if (index > -1 && client.isMenuOpen()) { RectangleDestination rect = getDestinationRect(index); success = client.moveMouse(rect, false); if (click && success) { client.clickMouse(false); } } return success; } public boolean isMouseOnOption(String action) { RectangleDestination rect = getDestinationRect(strOptions.indexOf(action)); return client.isMenuOpen() && rect.destinationReached(client.getMousePosition()); } } Edited December 31, 2013 by FrostBug 1 Link to comment Share on other sites More sharing options...