Jump to content

Buying items from general store


bumzag

Recommended Posts

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?

Link to comment
Share on other sites

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/ 

Link to comment
Share on other sites

  On 7/22/2019 at 9:09 PM, 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/ 

Expand  

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

Link to comment
Share on other sites

  On 7/22/2019 at 10:30 PM, 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

Expand  

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
Link to comment
Share on other sites

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
  • Sad 1
Link to comment
Share on other sites

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.

  • Like 1
Link to comment
Share on other sites

		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
  • Sad 1
  • Heart 1
Link to comment
Share on other sites

  On 7/22/2019 at 11:38 PM, 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.

Expand  

Thanks man, it was simple as a sleep statement. I'll have to work on ConditionalSleeps. Thank you.

 

  On 7/22/2019 at 11:46 PM, 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);
			}
		}

 

Expand  

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?

Link to comment
Share on other sites

  On 7/23/2019 at 12:08 AM, 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?

Expand  

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

Link to comment
Share on other sites

  On 7/23/2019 at 12:45 AM, bumzag said:

Ignore them in the sense that I can erase them out of the code?

Expand  

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
  • Like 1
Link to comment
Share on other sites

  On 7/23/2019 at 2:29 AM, 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);
			}
		}

 

Expand  

Ty for taking the time to answer. Makes a lot more sense now.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...