Jump to content

New scripter, wine bot not working.


bigd123
 Share

Recommended Posts

I'm trying to learn how to script, and am making a simple wine making script to start. This script works sometimes, but the but sometimes refuses to deposit, and just repeatedly openes and closes the bank until it decides to withdraw some random item. Any help appreciated(sorry I didin't comment the code)

package core;

import java.awt.Graphics2D;

import org.osbot.rs07.api.ui.RS2Widget;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;

@ScriptManifest(author = "bigd123", info = "Simple Wine Maker", name = "Wine Maker", version = 0, logo = "")
public class Main extends Script {
	public int min = 200;
	public int low = 400;
	@Override
	public void onStart() {
		log("Let's get started!");
	}
	//jug of water 1937, grape 1987
	@Override
	public int onLoop() throws InterruptedException {
		if (!myPlayer().isAnimating()) {
				objects.closest("Grand Exchange booth").interact();
				log("Opening bank");
				sleep(random(min,low));
				log("Depositing!");
				bank.depositAll();
				sleep(random(min,low));
				if(inventory.isEmpty()) { 
					log("Withdrawing!");			
					bank.withdraw(1987, 14);
					sleep(random(min,low));
					bank.withdraw(1937, 14);
					sleep(random(min,low));
				} else {
					bank.depositAll();
				}
				if(inventory.contains(1987) && inventory.contains(1937)){
					log("Closing Bank!");
					bank.close();
					log("Using items!");
					inventory.getItem(1987).interact("Use");
					sleep(random(min,low));
					inventory.getItem(1937).interact("Use");
					sleep(1000);
					RS2Widget makeWine = getWidgets().get(270,14,38);
					if (makeWine != null) {
						if (makeWine.isVisible());
						makeWine.interact();
						sleep(random(1300,1800));
					}
				
				}
		}
		return random(200, 300);
	}

	@Override
	public void onExit() {
		log("Bye!");
	}

	@Override
	public void onPaint(Graphics2D g) {
		int x = getMouse().getPosition().x;
		int y = getMouse().getPosition().y;
		g.drawLine(0, y, 765, y) ;
		g.drawLine(x, 0, x, 503);
	}
}

 

Link to comment
Share on other sites

sleep(random(min,low));

replace with conditionsleep,

log("Closing Bank!");
					bank.close();
					log("Using items!");
					inventory.getItem(1987).interact("Use");   // dont use id's use item names
					sleep(random(min,low));                    // use conditionsleep to sleep till you have actually  interacted with the item ( so lag doesnt fuck you up)
					inventory.getItem(1937).interact("Use");
					sleep(1000);

you say its not depositing sometimes, maybe add a check if bank is open -> deposit else -> open bank.    instead of doing it all in one block

Edited by zwaffel
Link to comment
Share on other sites

10 hours ago, bigd123 said:

I'm trying to learn how to script, and am making a simple wine making script to start. This script works sometimes, but the but sometimes refuses to deposit, and just repeatedly openes and closes the bank until it decides to withdraw some random item. Any help appreciated(sorry I didin't comment the code)


package core;

import java.awt.Graphics2D;

import org.osbot.rs07.api.ui.RS2Widget;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;

@ScriptManifest(author = "bigd123", info = "Simple Wine Maker", name = "Wine Maker", version = 0, logo = "")
public class Main extends Script {
	public int min = 200;
	public int low = 400;
	@Override
	public void onStart() {
		log("Let's get started!");
	}
	//jug of water 1937, grape 1987
	@Override
	public int onLoop() throws InterruptedException {
		if (!myPlayer().isAnimating()&& !getInventory.contains("Wine") { //######################################
				   if (!getBank().isOpen()) {////#############################
                getBank().open();
                
            }
				objects.closest("Grand Exchange booth").interact(); //--------

				log("Opening bank");
				sleep(random(min,low));
				log("Depositing!");
				bank.depositAll();
				sleep(random(min,low));
				if(inventory.isEmpty()&&getBank().isOpen()) { //##############################
					log("Withdrawing!");			
					bank.withdraw(1987, 14); //### you may want to change it to just the item name
					sleep(random(min,low));
					bank.withdraw(1937, 14);
					sleep(random(min,low));
				} else if (getinventory.contains("Wine"){//############################
					getBank.depositAll();
				}
				if(inventory.contains(1987) && inventory.contains(1937)){
					log("Closing Bank!");
					getBank.close();
					log("Using items!");
					inventory.getItem(1987).interact("Use");

					sleep(random(min,low));

					if(getInventory().isItemSelected()){ // this makes sure you have your first item selected before using it on the 2nd
					inventory.getItem(1937).interact("Use");
					sleep(1000);
					}

					RS2Widget makeWine = getWidgets().get(270,14,38);

//  You may want to look into the keyboard class, it could be easier, eg press and hold 1 while this widget is on screen
// just another way to do it :)
					if (makeWine != null) {
						if (makeWine.isVisible());
						
if (makeWine.interact()){ //you can totally use osbot's interact statements to see if you want to run some code, 
// in this case, if the interaction suceeds, we will sleep, if not, do nothing.
						sleep(random(1300,1800)); // ----- this is a big problem, it will cause you to repeat actions before your inventory is finished
                       //this spot needs a conditional sleep, but this are very annoying to implement, so instead let's use Explv's sleep class, located here:
					//https://osbot.org/forum/topic/127193-conditional-sleep-with-lambda-expressions/
					Sleep.sleepUntil(() -> !getInventory.contains("Jug of water"),int TOTALSLEEPTIME, int conditionCheckRate); 
}
					}
				
				}
		}
		return random(200, 300);
	}

	@Override
	public void onExit() {
		log("Bye!");
	}

	@Override
	public void onPaint(Graphics2D g) {
		int x = getMouse().getPosition().x;
		int y = getMouse().getPosition().y;
		g.drawLine(0, y, 765, y) ;
		g.drawLine(x, 0, x, 503);
	}
}

I added commented hastags for where you might want to change, and minuses for code to remove, I haven't tested but this should work. Just be sure to add code from Explv's(this man is a god btw, I'd be lost without his tuts) Sleep class.

You might want to add nullchecks and additional checks here and there, like to make sure your bank actually contains the items, else you might start getting nullpointer exceptions.

Once you get a few more scripts under your belt, look into some tuts on either enums, or task based scripting, as it gives you a lot of flow control for your scripts. And always read the api, once you know how to read what it's saying, it's extremely helpful.

 

Good luck, please let us know how it goes!

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.

 Share

  • Recently Browsing   0 members

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