xVirtus Posted November 28, 2019 Share Posted November 28, 2019 (edited) Hello, im quite new to writing these scripts, and just been messing with it this evening. I quickly stumbled into a problem when trying to script selling an item to the grand exchange, and i could not find any example on how to do this, so i experimented. My issue is, that an item does not get withdrawn from the bank properly, because of lack of sleeps or whatever, im not completely sure. if (!getBank().isOpen()) { getBank().open(); getBank().enableMode(Bank.BankMode.WITHDRAW_NOTE); } else if (getBank().contains("Kebab")) { Sleep.sleepUntil(() -> (getBank().withdrawAll("Kebab")), 5000); getBank().close(); } NPC geClerk = npcs.closest("Grand Exchange Clerk"); if (geClerk != null) { Sleep.sleepUntil(() -> (geClerk.interact("Exchange")), 5000); } If i have the code above, the kebabs will not be withdrawn when i have the geClerk interact line. Without it, it gets withdrawn fine, but with that line, it skips over the withdrawal and instantly opens the GE window instead. Hope i explained my issue well enough, and someone can give a helping hand. (if anyone has a code snippet that just grabs whatever item in a Note and lists it on GE for insta-sell price then that would be perfect too) Edited November 28, 2019 by xVirtus Quote Link to comment Share on other sites More sharing options...
Gunman Posted November 28, 2019 Share Posted November 28, 2019 @xVirtus } else if (getBank().contains("Kebab")) { if (getBank().withdrawAll("Kebab")) { Sleep.sleepUntil(() -> (!getBank().contains("Kebab")), 5000); getBank().close(); } } 1 Quote Link to comment Share on other sites More sharing options...
BravoTaco Posted November 28, 2019 Share Posted November 28, 2019 (edited) Before opening the ge you should also check to see if you have the kebabs. Also the sleep you are doing when you open the ge will end before it is open since you are just waiting for the click. You should change it to wait until the ge is open. Example If (geClerk != null && geClerk.interact("Exchange") Sleep.sleepUntil(() -> getGrandExchange().isOpen()); Sorry for the formating, on my phone atm. Edited November 28, 2019 by BravoTaco 1 1 Quote Link to comment Share on other sites More sharing options...
xVirtus Posted November 28, 2019 Author Share Posted November 28, 2019 (edited) of course, thanks for the help guys @BravoTaco my next line in the code was actually to wait untill the GE was open, but i chose not to include that part in the example just to make it a bit clearer, but i didnt have the interact call in the if statement Edited November 28, 2019 by xVirtus Quote Link to comment Share on other sites More sharing options...
Probability Posted November 28, 2019 Share Posted November 28, 2019 I find the scripts work better when I do one method per bracket. e.g. try not to do this if (condition){ domethod1; domethod2; domethod3; } But rather do this. if (condition1){ domethod1; if (condition2){ domethod2; if (condition3){ domethod3; } } } Quote Link to comment Share on other sites More sharing options...
xVirtus Posted November 28, 2019 Author Share Posted November 28, 2019 I tried doing this if (!getBank().isOpen()) { getBank().open(); getBank().enableMode(Bank.BankMode.WITHDRAW_NOTE); } else if (getBank().contains("Kebab")) { getBank().withdrawAll("Kebab"); Sleep.sleepUntil(() -> !getBank().contains("Kebab"),5000); } else if(getInventory().contains("Kebab")){ getBank().close(); } NPC geClerk = npcs.closest("Grand Exchange Clerk"); if (geClerk != null && geClerk.interact("Exchange")) { Sleep.sleepUntil(() -> (getGrandExchange().isOpen()), 5000); } else if (getGrandExchange().isOpen()){ getGrandExchange().sellItem(1971, 1, (int) getInventory().getAmount("Kebab")); Sleep.sleepUntil(this::canCollect, 5000); } But it still skips over the withdrawal of the kebabs from the bank. It seems to skip over the Sleep.sleepUntil(() -> !getBank().contains("Kebab"),5000); statement Quote Link to comment Share on other sites More sharing options...
BravoTaco Posted November 28, 2019 Share Posted November 28, 2019 (edited) You need to check if the kebabs are in your inventory before opening the exchange i believe what is happening is that if the bank is not open than you open the bank and than run the next code that would be opening the exchange. So it closes out of the bank before grabbing the kebabs. So something like this. If(getInventory().contains("kebabs") && geClerk != null && geClerk.interact("Exchange")) Take note of the order of which you are checking as well. If the check for null and the check for the ininteraction is before the kebabs it will still exit the bank and try to interact with the clerk. Again sorry for the formating still only have access to my phone atm. Edited November 28, 2019 by BravoTaco Quote Link to comment Share on other sites More sharing options...
xVirtus Posted November 28, 2019 Author Share Posted November 28, 2019 33 minutes ago, BravoTaco said: You need to check if the kebabs are in your inventory before opening the exchange i believe what is happening is that if the bank is not open than you open the bank and than run the next code that would be opening the exchange. So it closes out of the bank before grabbing the kebabs. So something like this. If(getInventory().contains("kebabs") && geClerk != null && geClerk.interact("Exchange")) Take note of the order of which you are checking as well. If the check for null and the check for the ininteraction is before the kebabs it will still exit the bank and try to interact with the clerk. Again sorry for the formating still only have access to my phone atm. ah of course, i'm a bit new to "async" programming like this botting API stuff, so i appreciate the help :). It does withdraw the kebabs without the GE code, which is why i was confused Quote Link to comment Share on other sites More sharing options...
Rare scripts Posted November 28, 2019 Share Posted November 28, 2019 (edited) if (!getInventory().contains("Kebab")) { if (getBank().isOpen()) { getBank().enableMode(Bank.BankMode.WITHDRAW_NOTE); if (getBank().contains("Kebab")) { getBank().withdrawAll("Kebab"); if (getBank().close()) { Sleep.sleepUntil(() -> !getBank().isOpen(), 9000); } } } else { if (getBank().open()) { Sleep.sleepUntil(() -> getBank().isOpen(), 9000); } } } else { NPC n = npcs.closest("Grand Exchange Clerk"); if (n != null) { if (n.interact("Exchange")) { Sleep.sleepUntil(() -> getGrandExchange().isOpen(), 9000); } } } I'm sorry if its messy, dont got a IDE here to make it look clean CTRL + SHIFT + F on eclipse would clean this for u. U can wrap around another boolean for if the grand exchange is open on this Sleep.sleepUntil(() -> (geClerk.interact("Exchange")), 5000); Here u do a interact in a sleep, i dont think that is possible (or would be accepted as a good way of making scripts) U dont need this code either: Sleep.sleepUntil(() -> !getBank().contains("Kebab"),5000); OSBot's api will handle the wait with only the withdraw function getBank().withdraw("Kebab"); is all u need Best of luck buddy! -Rare. Edited November 28, 2019 by Rare scripts 1 Quote Link to comment Share on other sites More sharing options...
xVirtus Posted November 28, 2019 Author Share Posted November 28, 2019 (edited) 9 minutes ago, Rare scripts said: if (!getInventory().contains("Kebab")) { if (getBank().isOpen()) { getBank().enableMode(Bank.BankMode.WITHDRAW_NOTE); if (getBank().contains("Kebab")) { getBank().withdrawAll("Kebab"); if (getBank().close()) { Sleep.sleepUntil(() -> !getBank().isOpen(), 9000); } } } else { if (getBank().open()) { Sleep.sleepUntil(() -> getBank().isOpen(), 9000); } } } else { NPC n = npcs.closest("Grand Exchange Clerk"); if (n != null) { if (n.interact("Exchange")) { Sleep.sleepUntil(() -> getGrandExchange().isOpen(), 9000); } } } I'm sorry if its messy, dont got a IDE here to make it look clean CTRL + SHIFT + F on eclipse would clean this for u. U can wrap around another boolean for if the grand exchange is open on this Sleep.sleepUntil(() -> (geClerk.interact("Exchange")), 5000); Here u do a interact in a sleep, i dont think that is possible (or would be accepted as a good way of making scripts) Best of luck buddy! -Rare. I did something sort of like this, and that worked and i finally figured out how to work the GE too, so my script is fully working right now. Dont know if i should release it or whatever, its still lacking stuff that could be improved, but it works. Buys kebabs untill out of cash in inventory then sells it on the GE This is what i ended up doing. Else-ifs were causing some errors, due to later statements would be executed out of order if (!getBank().isOpen()) { getBank().open(); if(!getInventory().isEmpty()) getBank().depositAll(); getBank().enableMode(Bank.BankMode.WITHDRAW_NOTE); } if (getBank().contains("Kebab")) { getBank().withdrawAll("Kebab"); Sleep.sleepUntil(() -> !getBank().contains("Kebab"),5000); } if(getInventory().contains("Kebab")){ getBank().close(); } instasell("Kebab"); private void instasell(String item){ NPC geClerk = npcs.closest("Grand Exchange Clerk"); if (getInventory().contains(item) && geClerk != null && geClerk.interact("Exchange")) { Sleep.sleepUntil(() -> (getGrandExchange().isOpen()), 5000); } if (getInventory().contains(item) && getGrandExchange().isOpen()){ Sleep.sleepUntil(() -> getInventory().getItem(item).interact("Offer"), 5000); ..... Edited November 28, 2019 by xVirtus 1 Quote Link to comment Share on other sites More sharing options...
Rare scripts Posted November 28, 2019 Share Posted November 28, 2019 3 minutes ago, xVirtus said: I did something sort of like this, and that worked and i finally figured out how to work the GE too, so my script is fully working right now. Dont know if i should release it or whatever, its still lacking stuff that could be improved, but it works. Buys kebabs untill out of cash in inventory then sells it on the GE This is what i ended up doing. Else-ifs were causing some errors, due to later statements would be executed out of order if (!getBank().isOpen()) { getBank().open(); if(!getInventory().isEmpty()) getBank().depositAll(); getBank().enableMode(Bank.BankMode.WITHDRAW_NOTE); } if (getBank().contains("Kebab")) { getBank().withdrawAll("Kebab"); Sleep.sleepUntil(() -> !getBank().contains("Kebab"),5000); } if(getInventory().contains("Kebab")){ getBank().close(); } instasell("Kebab"); private void instasell(String item){ NPC geClerk = npcs.closest("Grand Exchange Clerk"); if (getInventory().contains(item) && geClerk != null && geClerk.interact("Exchange")) { Sleep.sleepUntil(() -> (getGrandExchange().isOpen()), 5000); } if (getInventory().contains(item) && getGrandExchange().isOpen()){ Sleep.sleepUntil(() -> getInventory().getItem(item).interact("Offer"), 5000); ..... U should always use else if statements, If i can help with anything else feel free to shoot me a PM on discord. Quote Link to comment Share on other sites More sharing options...
xVirtus Posted November 28, 2019 Author Share Posted November 28, 2019 2 minutes ago, Rare scripts said: U should always use else if statements, If i can help with anything else feel free to shoot me a PM on discord. if i exchange the if, if, if with if, else if, else if then it breaks the program Quote Link to comment Share on other sites More sharing options...
Rare scripts Posted November 28, 2019 Share Posted November 28, 2019 1 minute ago, xVirtus said: if i exchange the if, if, if with if, else if, else if then it breaks the program I had to read this over twice Can u try with my snippet? This never failed for me personally. -Rare. Quote Link to comment Share on other sites More sharing options...
xVirtus Posted November 28, 2019 Author Share Posted November 28, 2019 Just now, Rare scripts said: I had to read this over twice Can u try with my snippet? This never failed for me personally. -Rare. haha, basically i figured out that it would enter the last else if statement, before running the previous one when using else if, rather than if. I will try using your snippet later and see if it works the same. Then probrably keep using that later. Only been messing with this since last night, and already made a functioning kebab buyer with GE selling 1 Quote Link to comment Share on other sites More sharing options...
Rare scripts Posted November 28, 2019 Share Posted November 28, 2019 1 minute ago, xVirtus said: haha, basically i figured out that it would enter the last else if statement, before running the previous one when using else if, rather than if. I will try using your snippet later and see if it works the same. Then probrably keep using that later. Only been messing with this since last night, and already made a functioning kebab buyer with GE selling Thats a great start buddy!! Wish u all the best! -Rare. 1 Quote Link to comment Share on other sites More sharing options...