Jump to content
View in the app

A better way to browse. Learn more.

OSBot :: 2007 OSRS Botting

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Buying items from general store

Featured Replies

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?

  • Author
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

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 by FuryShark

  • Author

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 by bumzag

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.

		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 by Naked

  • Author
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?

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

  • Author
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?

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 by Naked

  • Author
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.

Create an account or sign in to comment

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.