Jump to content

Simple buying script issue


Recommended Posts

Posted

Hi all, not wanting to get properly back into coding I just can't be bothered to buy grapes from the Culinaromancer chest. I wrote a little script but it doesn't seem to buy from the store. Is it because it's a chest, rather than an NPC? It will open up the shop & jump to the buying grapes method but it won't actually buy them.

Probably a simple fix but I'm rusty. Cheers.

 

package cookingTrainer;

import org.osbot.rs07.api.model.RS2Object;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;
import java.awt.*;

import javax.swing.text.html.parser.Entity;

@ScriptManifest(info = "GRAPE BUYER", version = 1.0, logo = "", author = "MATT", name = "")
public class main extends Script {
	
	enum State {
		OPENCHEST, BUYGRAPES, BANK, HOP;
	}

	public State state;
		
	public void onStart(){
		
	if(getInventory().isFull())
	{
			state = State.BANK;
			log("BANK");
	}
	
	if (getInventory().onlyContains("Coins"))
	{
		state = State.OPENCHEST;
		log("OPEN CHEST");
	}
	
	 if(getStore().isOpen())
	 {
		 state = State.BUYGRAPES;
	 }
	

	
	
	}
	
	public int onLoop() throws InterruptedException{
		switch (state){
		case OPENCHEST:
			return openChest();
		case BUYGRAPES:
			return buyGrapes();
		case BANK:
			return bank();
		case HOP:
			return hopWorlds();
		}
	return random(100, 220);
	}

	int openChest() throws InterruptedException {
		

		
		objects.closest("Chest").interact("Buy-food");
		sleep(900);	
		if (getInventory().contains("Coins") && !getInventory().isFull())
		{
			if (!getStore().contains("Grapes"))
			{
				state = State.HOP;
				log("HOPPING");
			}
			else
			{
				log("Changing state to buying");
				state = State.BUYGRAPES;
			
				
			}
		}
		return 0;
	}

	int buyGrapes() throws InterruptedException{
		
		log("BUYING");
		if (!getStore().contains("Grapes"))
		{		
			store.close();
			sleep(300);
			state = State.HOP;
			log("HOPPING");
		}
		else
		{
			log("BUYING GRAPES NOW");
			if (store.isOpen()) {
				log("store is open");
				sleep(300);
					store.buy("Grapes", 10);
					sleep(300);
					sleep(300);
					sleep(300);
				}
			}		
			sleep(300);	
		return 0;
	}

	int bank() throws InterruptedException{
		getBank().depositAllExcept("Coins");
		sleep(300);
		return 0;
	
	}
	
	int hopWorlds() throws InterruptedException
	{
		getWorlds().hopToP2PWorld();
		sleep(300);
		return 0;
		
	}

}

 

Posted
18 minutes ago, Gunman said:

@uyfgfarOS Trying interacting with the widget directly then. Also I think regardless the store will always contain grapes whether the amount is 0 or not. I never used the store api before so I don't know for sure.

I was trying to figure this out earlier, I can get the widget for the grape, but I can't figure out how I'd move the mouse cursor down to the buying option, as there isn't a widget for the mouse position I want.

Hmm okay cheers for that! Once I've got it buying I'll see if the hop method works or not.

Posted
6 minutes ago, uyfgfarOS said:

I was trying to figure this out earlier, I can get the widget for the grape, but I can't figure out how I'd move the mouse cursor down to the buying option, as there isn't a widget for the mouse position I want.

???
You just interact with it like you did with the chest
 

RS2Widget grapeWidget = getWidgets().getWidgetContainingText("Grapes");
        if (grapeWidget != null && grapeWidget.interact("What ever the buy interaction is")) {
            //sleeps
        }

And if there's a menu open, like when you right click, you can use the menuAPI to get the options and click on one.

Posted
28 minutes ago, Gunman said:

???
You just interact with it like you did with the chest
 


RS2Widget grapeWidget = getWidgets().getWidgetContainingText("Grapes");
        if (grapeWidget != null && grapeWidget.interact("What ever the buy interaction is")) {
            //sleeps
        }

And if there's a menu open, like when you right click, you can use the menuAPI to get the options and click on one.

Ah apologies mate, it's been a while haha! I'll try this out now. Appreciate it. 

 

Posted (edited)
41 minutes ago, Gunman said:

???
You just interact with it like you did with the chest
 




RS2Widget grapeWidget = getWidgets().getWidgetContainingText("Grapes");
        if (grapeWidget != null && grapeWidget.interact("What ever the buy interaction is")) {
            //sleeps
        }

And if there's a menu open, like when you right click, you can use the menuAPI to get the options and click on one.

Not finding any widget, It gets to the log stating the store is open, but won't get to the next log "buying 10"

 

if (store.isOpen()) {
				log("store is open");
				sleep(300);
				RS2Widget grapeWidget = getWidgets().getWidgetContainingText("Grapes");
		        	if (grapeWidget != null && grapeWidget.interact("Buy 10")) {
                 		 log("buying 10");
		        		 sleep(300);
		        }				
					

I then thought that the interact should be within the if statement, so I moved it there but still same results.

 

EDIT: Solved by just changing the widget declaration to     RS2Widget grapeWidge = getWidgets().get(300, 16, 5);

Edited by uyfgfarOS

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

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