Jump to content

Simple buying script issue


uyfgfarOS

Recommended Posts

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;
		
	}

}

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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. 

 

Link to comment
Share on other sites

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