bumzag Posted July 22, 2019 Share Posted July 22, 2019 Alright so I've evolved from cow killing and knife looting, I'm trying to make a shop buying script. I'm at the beginning right now, all I'm trying to do is test the simple function of interacting with the shop owner and clicking "Trade", and then buying 5 shovels from him. But nothing happens. NPC shopKeeper = getNpcs().closest("Shop keeper"); if (shopKeeper != null && shopKeeper.exists()) { shopKeeper.interact("Trade"); getStore().buy("Spade, 5); } What am I doing wrong? Quote Link to comment Share on other sites More sharing options...
FuryShark Posted July 22, 2019 Share Posted July 22, 2019 Make sure the shop is open before you try buying things getStore().isOpen() getStore().buy("Spade your missing a " at the end of spade... Use conditional sleeps so you dont end up spam clicking trade https://osbot.org/forum/topic/127193-conditional-sleep-with-lambda-expressions/ Quote Link to comment Share on other sites More sharing options...
bumzag Posted July 22, 2019 Author Share Posted July 22, 2019 1 hour ago, FuryShark said: Make sure the shop is open before you try buying things getStore().isOpen() getStore().buy("Spade your missing a " at the end of spade... Use conditional sleeps so you dont end up spam clicking trade https://osbot.org/forum/topic/127193-conditional-sleep-with-lambda-expressions/ Like this? NPC shopKeeper = getNpcs().closest("Shop keeper"); if (shopKeeper != null && shopKeeper.exists()) { shopKeeper.interact("Trade"); if(getStore().isOpen()) getStore().buy("Spade", 5); } Still not yielding anything Quote Link to comment Share on other sites More sharing options...
FuryShark Posted July 22, 2019 Share Posted July 22, 2019 (edited) 22 minutes ago, bumzag said: Like this? NPC shopKeeper = getNpcs().closest("Shop keeper"); if (shopKeeper != null && shopKeeper.exists()) { shopKeeper.interact("Trade"); if(getStore().isOpen()) getStore().buy("Spade", 5); } Still not yielding anything Works for me, try adding logs to see where your getting stuck. Also make sure your pressing refresh before trying to run it after you export a new version of a script. Edited July 22, 2019 by FuryShark Quote Link to comment Share on other sites More sharing options...
bumzag Posted July 22, 2019 Author Share Posted July 22, 2019 (edited) Yeah dude idk what's going on. It trades with the shop keeper, outputs the log, waits a second, closes the shop and repeats. But it won't buy. Edit: on second thought, the log in the if(getStore().isOpen()) doesn't output, there fore it doesn't buy either. Also, I did refresh on the script GUI, and I know it did take the rebuild of the jar file because I changed the log string that's outside the if(getStore().isOpen() statement. Edited July 22, 2019 by bumzag 1 Quote Link to comment Share on other sites More sharing options...
dreameo Posted July 22, 2019 Share Posted July 22, 2019 You want to do a conditional sleep on the opening of the store: if(shopKeeper.interact("Trade"){ sleep.SleepUntil(../*getStore.isOpen()*/..); getStore().buy("Spade", 5); } The issue I believe is that when the "getStore.isOpen()" call is made, the shop has not already opened (perhaps a few ms delay). You could also try throwing a regular sleep inbetween if you didn't want to do a conditional sleep. 1 Quote Link to comment Share on other sites More sharing options...
Naked Posted July 22, 2019 Share Posted July 22, 2019 (edited) Position shop = new Position(###,###,###); if (s.myPlayer().getPosition().distance(shop) > 10) { WebWalkEvent event = new WebWalkEvent(shop); s.execute(event); } NPC ShopKeeper = s.npcs.closest("Shop keeper"); if (ShopKeeper.exists()) { if (ShopKeeper.isVisible()) { if (!s.store.isOpen()) { ShopKeeper.interact("Trade"); Sleep.sleepUntil(() -> s.store.isOpen(), 5000); } } } if (s.store.isOpen()) { if (!s.inventory.contains("Spade")) { Sleep.sleepUntil(() -> s.store.buy("Spade", 5), 5000); } } Edited July 23, 2019 by Naked 1 1 Quote Link to comment Share on other sites More sharing options...
bumzag Posted July 23, 2019 Author Share Posted July 23, 2019 26 minutes ago, dreameo said: You want to do a conditional sleep on the opening of the store: if(shopKeeper.interact("Trade"){ sleep.SleepUntil(../*getStore.isOpen()*/..); getStore().buy("Spade", 5); } The issue I believe is that when the "getStore.isOpen()" call is made, the shop has not already opened (perhaps a few ms delay). You could also try throwing a regular sleep inbetween if you didn't want to do a conditional sleep. Thanks man, it was simple as a sleep statement. I'll have to work on ConditionalSleeps. Thank you. 18 minutes ago, Naked said: Position shop = new Position(###,###,###); if (s.myPlayer().getPosition().distance(shop) > 10) { WebWalkEvent event = new WebWalkEvent(shop); s.execute(event); } NPC ShopKeeper = s.npcs.closest("Shop keeper"); if (ShopKeeper.exists()) { if (ShopKeeper.isVisible()) { if (!s.store.isOpen()) { ShopKeeper.interact("Trade"); Sleep.sleepUntil(() -> s.store.isOpen(), 5000); } } } if (s.store.isOpen()) { if (!s.inventory.contains("Hammer")) { Sleep.sleepUntil(() -> s.store.buy("Spade", 5), 5000); } } Thank you for writing that out. Can you elaborate on stuff like "s.store.isOpen()" and "s.myPlayer().getPosition().distance(shop)" and "s.npcs.closest("Shop keeper")"? I don't understand the "s." portion of it. Where is that coming from? Quote Link to comment Share on other sites More sharing options...
Naked Posted July 23, 2019 Share Posted July 23, 2019 21 minutes ago, bumzag said: Thank you for writing that out. Can you elaborate on stuff like "s.store.isOpen()" and "s.myPlayer().getPosition().distance(shop)" and "s.npcs.closest("Shop keeper")"? I don't understand the "s." portion of it. Where is that coming from? You can ignore those in your case. I just copy and pasted some code. The s is short for script, a variable in my Task class. The class this was from extended the Task class. TL;DR ignore it Quote Link to comment Share on other sites More sharing options...
bumzag Posted July 23, 2019 Author Share Posted July 23, 2019 6 minutes ago, Naked said: You can ignore those in your case. I just copy and pasted some code. The s is short for script, a variable in my Task class. The class this was from extended the Task class. TL;DR ignore it Ignore them in the sense that I can erase them out of the code? Quote Link to comment Share on other sites More sharing options...
Naked Posted July 23, 2019 Share Posted July 23, 2019 (edited) 1 hour ago, bumzag said: Ignore them in the sense that I can erase them out of the code? Right so enter the position and this code should work for you. This uses this sleep class: Position shop = new Position(###,###,###); if (myPlayer().getPosition().distance(shop) > 10) { WebWalkEvent event = new WebWalkEvent(shop); execute(event); } NPC ShopKeeper = npcs.closest("Shop keeper"); if (ShopKeeper.exists()) { if (ShopKeeper.isVisible()) { if (!store.isOpen()) { ShopKeeper.interact("Trade"); Sleep.sleepUntil(() -> store.isOpen(), 5000); } } } if (store.isOpen()) { if (!inventory.contains("Spade")) { Sleep.sleepUntil(() -> store.buy("Spade", 5), 5000); } } Edited July 23, 2019 by Naked 1 Quote Link to comment Share on other sites More sharing options...
bumzag Posted July 23, 2019 Author Share Posted July 23, 2019 9 hours ago, Naked said: Right so enter the position and this code should work for you. This uses this sleep class: Position shop = new Position(###,###,###); if (myPlayer().getPosition().distance(shop) > 10) { WebWalkEvent event = new WebWalkEvent(shop); execute(event); } NPC ShopKeeper = npcs.closest("Shop keeper"); if (ShopKeeper.exists()) { if (ShopKeeper.isVisible()) { if (!store.isOpen()) { ShopKeeper.interact("Trade"); Sleep.sleepUntil(() -> store.isOpen(), 5000); } } } if (store.isOpen()) { if (!inventory.contains("Spade")) { Sleep.sleepUntil(() -> store.buy("Spade", 5), 5000); } } Ty for taking the time to answer. Makes a lot more sense now. Quote Link to comment Share on other sites More sharing options...