The Undefeated Posted April 9, 2017 Share Posted April 9, 2017 (edited) Simple snippet to abort all offers if they have status x. private boolean toAbortOffers() { return !getWidgets().containingActions(465,"Abort offer").isEmpty(); } private void abortOffers() throws InterruptedException { if (toAbortOffers()) { ArrayList<RS2Widget> toAbort = (ArrayList<RS2Widget>) getWidgets().containingActions(465,"Abort offer"); for (int i = 0; i < toAbort.size(); i++) { toAbort.get(i).interact("Abort offer"); int finalI = i; new ConditionalSleep(10000) { @Override public boolean condition() { return Arrays.asList(toAbort.get(finalI).getInteractOptions()).contains("Abort offer"); } }.sleep(); } sleep(random(800,1200)); getGrandExchange().collect(); } } If you see any improvements I could make, don't hesitate to comment. https://gyazo.com/bf50191011b0d8fd69b67ae4ea55da53 Edited April 29, 2017 by The Undefeated 2 Quote Link to comment Share on other sites More sharing options...
Token Posted April 9, 2017 Share Posted April 9, 2017 If you are looking for improvements I guess you could start by removing any constant number that you can't justify ("magic numbers" in programming), I see at least 4 of them in the 2nd method, and another 2 which will make your code unstable Quote Link to comment Share on other sites More sharing options...
The Undefeated Posted April 9, 2017 Author Share Posted April 9, 2017 1 minute ago, Token said: If you are looking for improvements I guess you could start by removing any constant number that you can't justify ("magic numbers" in programming), I see at least 4 of them in the 2nd method, and another 2 which will make your code unstable G.E. Box 1 has widget number 7, Box 2 has 8 etc. That's why. Quote Link to comment Share on other sites More sharing options...
Token Posted April 9, 2017 Share Posted April 9, 2017 Just now, The Undefeated said: G.E. Box 1 has widget number 7, Box 2 has 8 etc. That's why. That's 1 of the 2 which makes your code unstable Quote Link to comment Share on other sites More sharing options...
The Undefeated Posted April 9, 2017 Author Share Posted April 9, 2017 Just now, Token said: That's 1 of the 2 which makes your code unstable Please tell me how I could improve that? Other one must be the static widget (Which is almost impossible to replace or the sleep. Quote Link to comment Share on other sites More sharing options...
Token Posted April 9, 2017 Share Posted April 9, 2017 Just now, The Undefeated said: Please tell me how I could improve that? Other one must be the static widget (Which is almost impossible to replace or the sleep. I don't see why it's impossible to replace, the id is just one of the many properties a RS2Widget object has. Take a look through all methods, there's at least 10 different ways of identifying a widget and id is only 1 of them (easiest and worst at the same time) https://osbot.org/api/org/osbot/rs07/api/ui/RS2Widget.html eg: filter by actions, filter by position, filter by message, filter by color BUT NOT filter by id. The simple reason behind this is the properties I mentioned are all exposed to the human player, while abstract numbers such as ids and indexes are not visible to normal players, and jagex can change them whenever they want without affecting the legit players. They do this about once a month for the tutorial island widgets just to break all scripts coded by people who use these properties. As for the sleeps, if I ask you why 300 and not 301, and you can't give a serious answer to this, then it is an obviously flawed logic. A better approach would be waiting until something happens aka conditional sleep. 4 Quote Link to comment Share on other sites More sharing options...
k9thebeast Posted April 9, 2017 Share Posted April 9, 2017 Just now, Token said: As for the sleeps, if I ask you why 300 and not 301, and you can't give a serious answer to this, then it is an obviously flawed logic. A better approach would be waiting until something happens aka conditional sleep. 300 looks better than 301, shaboom. Srslly tho, what token said. Quote Link to comment Share on other sites More sharing options...
The Undefeated Posted April 9, 2017 Author Share Posted April 9, 2017 (edited) 1 hour ago, Token said: I don't see why it's impossible to replace, the id is just one of the many properties a RS2Widget object has. Take a look through all methods, there's at least 10 different ways of identifying a widget and id is only 1 of them (easiest and worst at the same time) https://osbot.org/api/org/osbot/rs07/api/ui/RS2Widget.html eg: filter by actions, filter by position, filter by message, filter by color BUT NOT filter by id. The simple reason behind this is the properties I mentioned are all exposed to the human player, while abstract numbers such as ids and indexes are not visible to normal players, and jagex can change them whenever they want without affecting the legit players. They do this about once a month for the tutorial island widgets just to break all scripts coded by people who use these properties. As for the sleeps, if I ask you why 300 and not 301, and you can't give a serious answer to this, then it is an obviously flawed logic. A better approach would be waiting until something happens aka conditional sleep. Thanks for clearing this up, I improved it. Only part I don't like is the sleep before collecting. If I don't add it, the last 1-2 items that were aborted won't be collected. And it also presses the same exact position on all of the boxes. Edited April 9, 2017 by The Undefeated Quote Link to comment Share on other sites More sharing options...
Final Posted April 9, 2017 Share Posted April 9, 2017 No point using a List when you are using it like an Array. Quote Link to comment Share on other sites More sharing options...
The Undefeated Posted April 9, 2017 Author Share Posted April 9, 2017 20 minutes ago, Final said: No point using a List when you are using it like an Array. Changed it. Quote Link to comment Share on other sites More sharing options...
TheGreatests Posted April 25, 2017 Share Posted April 25, 2017 Looks good man, thank you for the snippet Quote Link to comment Share on other sites More sharing options...