LoudPacks Posted July 6, 2016 Share Posted July 6, 2016 (edited) protected abstract static class Widgets { public static boolean containsText(int parent, int child, String text) { RS2Widget widget = s.getWidgets().get(parent, child); if (exists(widget) && widget.isVisible()) { return widget.getMessage().contains(text); } return false; } public static boolean interactTil(String action, int i, int j, int k, ConditionalSleep con) { RS2Widget widget = s.getWidgets().get(i, j, k); if (exists(widget)) { widget.interact(action); con.sleep(); return true; } return false; } public static String getText(int i, int j) { RS2Widget widget = s.getWidgets().get(i, j); if (exists(widget) && widget.isVisible()) { return widget.getMessage(); } return ""; } private static boolean exists(RS2Widget widget) { return widget != null; } public static boolean interactTil(String action, int parent, int child, ConditionalSleep con) { RS2Widget widget = s.getWidgets().get(parent, child); if (exists(widget)) { widget.interact(action); con.sleep(); return true; } return false; } public static boolean interactTilNull(String action, int parent, int child) { RS2Widget widget = s.getWidgets().get(parent, child); if (exists(widget)) { widget.interact(action); new ConditionalSleep(2500, 3000) { @Override public boolean condition() { return !exists(widget); } }.sleep(); return true; } return false; } public static boolean interactTilNull(String action, int parent, int child, int child2) { RS2Widget widget = s.getWidgets().get(parent, child, child2); if (exists(widget)) { widget.interact(action); new ConditionalSleep(2500, 3000) { @Override public boolean condition() { return !exists(widget); } }.sleep(); return true; } return false; } } protected abstract static class Trade { public static boolean isTrading() { return s.getTrade().isCurrentlyTrading() || s.getTrade().isFirstInterfaceOpen() || s.getTrade().isSecondInterfaceOpen(); } public static void trade(String name, HashMap<String, Integer> itemSet, boolean acceptLast) { String cleanName = name.replaceAll(" ", "\\u00a0"); Player player = s.getScript().getPlayers().closest(cleanName); if (player != null && !isTrading() && player.interact("trade with")) { new ConditionalSleep(3000, 4000) { @Override public boolean condition() { return isTrading(); } }.sleep(); } if (isTrading() && s.getTrade().isFirstInterfaceOpen()) { if (!tradeOfferMatches(itemSet)) { for (String item : itemSet.keySet()) { if (!s.getTrade().getOurOffers().contains(item)) { if (s.getTrade().offer(item, itemSet.get(item))) { new ConditionalSleep(2000, 3000) { @Override public boolean condition() { return s.getTrade().getOurOffers().contains(item); } }.sleep(); } } } } else { if (acceptLast && s.getTrade().didOtherAcceptTrade()) { if (Widgets.interactTil("Accept", 335, 11, new ConditionalSleep(1500, 2000) { @Override public boolean condition() { return s.getTrade().isSecondInterfaceOpen(); } })) { new ConditionalSleep(3000, 4000) { @Override public boolean condition() { return s.getTrade().isSecondInterfaceOpen(); } }.sleep(); } } else if (!acceptLast && !hasAccepted()) { if (Widgets.interactTil("Accept", 335, 11, new ConditionalSleep(1500, 2000) { @Override public boolean condition() { return hasAccepted(); } })) { new ConditionalSleep(3000, 4000) { @Override public boolean condition() { return s.getTrade().isSecondInterfaceOpen(); } }.sleep(); } } } } else if (isTrading() && s.getTrade().isSecondInterfaceOpen()) { if (acceptLast && s.getTrade().didOtherAcceptTrade()) { if (Widgets.interactTil("Accept", 334, 25, new ConditionalSleep(1500, 2000) { @Override public boolean condition() { return !isTrading(); } })) { new ConditionalSleep(3000, 4000) { @Override public boolean condition() { return s.getTrade().isSecondInterfaceOpen(); } }.sleep(); } } else if (!acceptLast && !hasAccepted()) { if (Widgets.interactTil("Accept", 334, 25, new ConditionalSleep(1500, 2000) { @Override public boolean condition() { return !isTrading(); } })) { new ConditionalSleep(3000, 4000) { @Override public boolean condition() { return s.getTrade().isSecondInterfaceOpen(); } }.sleep(); } } } } private static boolean hasAccepted() { return Widgets.containsText(335, 30, "Waiting for other player...") || Widgets.containsText(334, 4, "Waiting for other player..."); } private static boolean tradeOfferMatches(HashMap<String, Integer> itemSet) { for (String item : itemSet.keySet()) { if (isTrading() && s.getTrade().getOurOffers().getItem(item) == null) { s.log("Trade Offer Missing: " + item); return false; } } return true; } } Note: you can make it non static / abstract just remove the s.* thats just how my api is. Usage: HashMap<String, Integer> itemMap = new HashMap<String, Item>(); itemMap.put("Shark", 12); itemMap.put("Coins", 42069); private int onLoop(){ if(shouldTrade()) trade("Zezima", itemMap, false); //trades zezima the itemMap and doesnt wait for them to accept. return 250; } Edited July 6, 2016 by LoudPacks 1 Quote Link to comment Share on other sites More sharing options...
Botre Posted July 6, 2016 Share Posted July 6, 2016 public static boolean interactTil(String action, int i, int j, int k ... Parameter names Quote Link to comment Share on other sites More sharing options...
LoudPacks Posted July 6, 2016 Author Share Posted July 6, 2016 public static boolean interactTil(String action, int i, int j, int k ... Parameter names Just had 2 params before and auto added method lol Quote Link to comment Share on other sites More sharing options...
Antonio Kala Posted July 6, 2016 Share Posted July 6, 2016 I don't get it who are you trading? Quote Link to comment Share on other sites More sharing options...
LoudPacks Posted July 6, 2016 Author Share Posted July 6, 2016 I don't get it who are you trading? Whoever you want Quote Link to comment Share on other sites More sharing options...
Chris Posted July 8, 2016 Share Posted July 8, 2016 Nice Quote Link to comment Share on other sites More sharing options...
Trump Posted July 18, 2016 Share Posted July 18, 2016 ummm, trying to learn java and just looked at this. Looks so fucking confusing. Quote Link to comment Share on other sites More sharing options...
Duhstin Posted August 2, 2016 Share Posted August 2, 2016 Thank you. I use auto-muling and this may come in handy. Quote Link to comment Share on other sites More sharing options...