Ricky Dactyl Posted July 30, 2018 Share Posted July 30, 2018 (edited) For whatever reason I couldn't get the OSBot's allocated API section regarding finding items in the bank to work, so I came up with my own method to do so. Calling the BankManager object within your main script class. The Class package com.shrykur.bots.thieving; import java.awt.Rectangle; import org.osbot.rs07.Bot; import org.osbot.rs07.api.Bank; import org.osbot.rs07.api.Mouse; import org.osbot.rs07.api.model.Item; import org.osbot.rs07.input.mouse.RectangleDestination; import org.osbot.rs07.script.Script; import org.osbot.rs07.utility.Condition; public class BankManager { private Bot bot; private Mouse mouse; private Bank bank; private boolean canSee; private Script script; public BankManager(Script script) { this.script = script; this.bot = script.getBot(); this.mouse = script.getMouse(); this.bank = script.getBank(); canSee = false; } public boolean containsItem(String name) { if (this.bank.contains(name)) { return true; } return false; } public boolean isVisible(String name) { this.canSee = this.bank.isSlotVisible(bot, getSlot(name), getSlot(name)); return this.canSee; } @SuppressWarnings("static-access") public void withdrawItem(String name, int amount) { if (!this.isVisible(name)) { // Moves scroll bar to the top of the bank this.mouse.click(new RectangleDestination(bot, new Rectangle(482, 99, 10, 1))); // Holds left click on downward arrow until item is visible RectangleDestination rd = new RectangleDestination(bot, new Rectangle(482, 280, 3, 10)); this.mouse.continualClick(rd, new Condition() { @Override public boolean evaluate() { return isVisible(name); } }, false); } switch (amount) { case 1: { this.getItem(name).interact("Withdraw-1"); break; } case 5: { this.getItem(name).interact("Withdraw-5"); break; } case 10: { this.getItem(name).interact("Withdraw-10"); break; } default: { try { this.getItem(name).interact("Withdraw-X"); this.script.sleep(1000); this.script.getKeyboard().typeString(String.valueOf(amount)); } catch (InterruptedException e) { e.printStackTrace(); } break; } } } public void depositInventory() { if (this.bank.isOpen()) { this.mouse.click(new RectangleDestination(bot, new Rectangle(430, 297, 24, 30))); } } public Item getItem(String name) { return this.bank.getItem(name); } public int getSlot(String name) { return this.bank.getSlot(name); } public void close() { this.bank.close(); } } Notes: WithdrawItem(String, Integer) will automatically find the item within your bank. This class is not completed, it's simply what I came up and use for the specific problem of finding and withdrawing a particular item from the bank. BankManager.java Edited July 30, 2018 by Ricky Dactyl Quote Link to comment Share on other sites More sharing options...
Alek Posted July 30, 2018 Share Posted July 30, 2018 Oof this is not good. The class is called Bank, you're using a lot of static widget ids which will certainly break over the course of a month. API should be the most stable part of your script and never break. The getRandomInteger stuff is a bit confusing as well, what you could do is get a random point in the rectangle of the widget, since you wouldn't want to misclick? Also wouldn't withdrawing one at a time instead of Withdraw-10/Withdraw-X be less "bot like"? I'm not quite understanding this part: this.mouse.click(new RectangleDestination(bot, new Rectangle(482, 99, 10, 0))); This means you can only withdraw an item at a very specific slot on a very specific tab setup? Hopefully you take it constructively, sorry if I came off as rude. 1 Quote Link to comment Share on other sites More sharing options...
Ricky Dactyl Posted July 30, 2018 Author Share Posted July 30, 2018 (edited) 27 minutes ago, Alek said: Oof this is not good. The class is called Bank, you're using a lot of static widget ids which will certainly break over the course of a month. API should be the most stable part of your script and never break. The getRandomInteger stuff is a bit confusing as well, what you could do is get a random point in the rectangle of the widget, since you wouldn't want to misclick? Also wouldn't withdrawing one at a time instead of Withdraw-10/Withdraw-X be less "bot like"? Also I'm not understanding this part: this.mouse.click(new RectangleDestination(bot, new Rectangle(482, 99, 10, 0))); This means you can only withdraw an item at a very specific slot on a very specific tab setup? Hopefully you take it constructively, sorry if I came off as rude. Hey my dude, Hopefully I can shed some light, the built in Bank within OSBot was open/closing repeatedly without finding the slot requested, the only widget ID I've used is the one for this specific widget I wasn't aware widget ID's changed (I've only been developing for Runescape scripts for a few days.) this.mouse.click(new RectangleDestination(bot, new Rectangle(482, 99, 10, 0))); was specifically to ensure that the slider in the bank is moved to the top most possible point. The drawing out of items singularly was used because it's a personal class I've developed, I was simply putting it here encase anyone had a similar problem to mine then it would help them, either by taking the class as a whole and changing it to their needs or simply taking a specific set of code. Hopefully this has cleared up any questions you had @Alek, I'd like to hear back about the widget ID's if you don't mind ^_^ Edited July 30, 2018 by Ricky Dactyl 1 Quote Link to comment Share on other sites More sharing options...
Alek Posted July 30, 2018 Share Posted July 30, 2018 32 minutes ago, Shrykur said: Hey my dude, Hopefully I can shed some light, the built in Bank within OSBot was open/closing repeatedly without finding the slot requested, the only widget ID I've used is the one for this specific widget I wasn't aware widget ID's changed (I've only been developing for Runescape scripts for a few days.) this.mouse.click(new RectangleDestination(bot, new Rectangle(482, 99, 10, 0))); was specifically to ensure that the slider in the bank is moved to the top most possible point. The drawing out of items singularly was used because it's a personal class I've developed, I was simply putting it here encase anyone had a similar problem to mine then it would help them, either by taking the class as a whole and changing it to their needs or simply taking a specific set of code. Hopefully this has cleared up any questions you had @Alek, I'd like to hear back about the widget ID's if you don't mind ^_^ Sounds like you were doing something not quite right. If you were using slot ids, then they were probably wrong (common mistake). Opening/closing the bank repeatedly sounds like a script problem, not OSBot. Visibility can be done by the widget of the slot which is your destination, however you can get the SlotDestination using default Bank methods. The deposit all button can be scanned for using sprite ids. Edit: I like that you were at least trying some solutions to your problem instead of giving up 1 Quote Link to comment Share on other sites More sharing options...
Ricky Dactyl Posted July 30, 2018 Author Share Posted July 30, 2018 (edited) 31 minutes ago, Alek said: Sounds like you were doing something not quite right. If you were using slot ids, then they were probably wrong (common mistake). Opening/closing the bank repeatedly sounds like a script problem, not OSBot. Visibility can be done by the widget of the slot which is your destination, however you can get the SlotDestination using default Bank methods. The deposit all button can be scanned for using sprite ids. Edit: I like that you were at least trying some solutions to your problem instead of giving up I took what you @Alek into consideration about widgets and based it purely from client mouse location (updated the class btw), the class no longer uses widgets and uses a less bot like withdraw method while catering for specific amounts of items being withdrawn. Encase someone stumbles upon this thread in the future with the same issue as mine, it should futureproof them. Also worth mentioning, I was using a getItemSlot method within the OSBot API alongside the isSlotVisible method also from the OSBot API, I'm sure on sub-level it was something I was misusing in some shape or form. Thanks for the thoughts on Widgets Edited July 30, 2018 by Ricky Dactyl Quote Link to comment Share on other sites More sharing options...
liverare Posted July 31, 2018 Share Posted July 31, 2018 Alek's simply jealous he'd never thought of: public boolean containsItem(String name) { if (this.bank.contains(name)) { return true; } return false; } Success breeds jealousy. 1 Quote Link to comment Share on other sites More sharing options...
Ricky Dactyl Posted August 3, 2018 Author Share Posted August 3, 2018 On 7/31/2018 at 3:27 PM, liverare said: Alek's simply jealous he'd never thought of: public boolean containsItem(String name) { if (this.bank.contains(name)) { return true; } return false; } Success breeds jealousy. I mean more or less the whole reason for this class was to do with this portion of the code, but okay. public void withdrawItem(String name, int amount) { if (!this.isVisible(name)) { // Moves scroll bar to the top of the bank this.mouse.click(new RectangleDestination(bot, new Rectangle(482, 99, 10, 1))); // Holds left click on downward arrow until item is visible RectangleDestination rd = new RectangleDestination(bot, new Rectangle(482, 280, 3, 10)); this.mouse.continualClick(rd, new Condition() { @Override public boolean evaluate() { return isVisible(name); } }, false); } switch (amount) { case 1: { this.getItem(name).interact("Withdraw-1"); break; } case 5: { this.getItem(name).interact("Withdraw-5"); break; } case 10: { this.getItem(name).interact("Withdraw-10"); break; } default: { try { this.getItem(name).interact("Withdraw-X"); this.script.sleep(1000); this.script.getKeyboard().typeString(String.valueOf(amount)); } catch (InterruptedException e) { e.printStackTrace(); } break; } } } Quote Link to comment Share on other sites More sharing options...
liverare Posted August 3, 2018 Share Posted August 3, 2018 10 hours ago, Shrykur said: I mean more or less the whole reason for this class was to do with this portion of the code, but okay. I know. I supposed a bit of critique I have are: Don't suppress warnings. If you're being told you can reference something statically, you should. Don't add and then modified delegate methods unless it makes sense. The thing I was mocking you for was the fact that 'this.bank.contains' returns a bool and you could have simply returned that in your 'containsItem' method. Similar thing for your 'close' method. OSBot has an InterruptedException handler, so you don't have to add your own. Instead, have your methods throw that exception up the stack. You're effectively making an API, albeit an extension to the Bank API. Instead of defining mouse, keyboard, script, etc. just extend 'org.osbot.rs07.script.API' on your class, instantiate a new object of that class and call its 'exchangeContext' function and 'initialiseModule' function (in that order). That gives you access to all the internal APIs. You can see an example here. Your 'withdrawItem' function is flawed in the human sense. If I have to withdraw 2 of something, I'm not going to be performing a 'withdraw-X', but I bet Jagex performs a little check of players who do. If the action requires maybe more than 5 mouse actions, then perhaps withdraw by X amount. By 5 mouse actions, that includes withdrawing 5 and 10, then left-clicking the rest. Have fun writing that AI. 1 Quote Link to comment Share on other sites More sharing options...
Ricky Dactyl Posted August 4, 2018 Author Share Posted August 4, 2018 On 8/3/2018 at 12:32 PM, liverare said: I know. I supposed a bit of critique I have are: Don't suppress warnings. If you're being told you can reference something statically, you should. Don't add and then modified delegate methods unless it makes sense. The thing I was mocking you for was the fact that 'this.bank.contains' returns a bool and you could have simply returned that in your 'containsItem' method. Similar thing for your 'close' method. OSBot has an InterruptedException handler, so you don't have to add your own. Instead, have your methods throw that exception up the stack. You're effectively making an API, albeit an extension to the Bank API. Instead of defining mouse, keyboard, script, etc. just extend 'org.osbot.rs07.script.API' on your class, instantiate a new object of that class and call its 'exchangeContext' function and 'initialiseModule' function (in that order). That gives you access to all the internal APIs. You can see an example here. Your 'withdrawItem' function is flawed in the human sense. If I have to withdraw 2 of something, I'm not going to be performing a 'withdraw-X', but I bet Jagex performs a little check of players who do. If the action requires maybe more than 5 mouse actions, then perhaps withdraw by X amount. By 5 mouse actions, that includes withdrawing 5 and 10, then left-clicking the rest. Have fun writing that AI. I respect your input and thank you for doing so, I'd rather you just tell me straight up rather than mock any work that anyone contributes, it's more productive that way. I completely agree with everything you said however for me this was just a quick fix for an issue I was having while suicide bottling some seeds, thank you though! Quote Link to comment Share on other sites More sharing options...