Jump to content
Sophisticated

Withdrawing items and using items on each other.

Recommended Posts

Hi guys, I'm trying to train my 'skills', by making a simple potion maker. Currently the potion maker is supposed to make simple (unf) guam potions, but I'm having trouble with two things.

When I start the script with an empty inventory near a bank, the script opens the bank and is supposed to withdraw 14 water vials and 14 guams. At the moment I'm able to open the bank and withdraw the items IF I delete this part of the code: if (herb.length >= 14 && waterVial.length >= 14) line 25.

And the second problem I'm having is with using items on each other, I'm currently able to click on an item, but that's pretty much it. I tried searching the docs and forums for these two problems, but without succes. So I actually have 3 questions:

- How can I check if I have items on my bank? (answered)

- How can I use two items on each other? (answered)

- If you guys were on my spot right now and you had to use the docs for these two problems, how would you find the right methods for this?

 

The code is below, I'm hoping someone can answer one or more questions.

 

package scripts;

import org.tribot.api2007.Banking;
import org.tribot.api2007.Inventory;
import org.tribot.api2007.types.RSItem;
import org.tribot.script.Script;
import org.tribot.script.ScriptManifest;

@ScriptManifest(authors = {
		"Sophisticated" }, category = "Herblore", name = "Sophisticated's Potion Maker", version = 1.00, description = "Makes dem pots XD.", gameMode = 1)
public class Herblore extends Script
{

	private void withdrawIngredients()
	{
		if (!Banking.isBankScreenOpen())
		{
			Banking.openBank();
		}
		else if (Banking.isBankScreenOpen())
		{
			RSItem[] herb = Banking.find(249);
			RSItem[] waterVial = Banking.find(227);

			if (herb.length >= 14 && waterVial.length >= 14)
			{
				Banking.withdraw(14, 249);
				Banking.withdraw(14, 227);
				Banking.close();
			}
		}
	}

	public boolean gotIngredients()
	{
		RSItem[] herb = Inventory.find(249);
		RSItem[] waterVial = Inventory.find(227);
		if (herb.length == 14 && waterVial.length == 14)
		{
			return true;
		}
		return false;
	}

	public void MakePots()
	{
		RSItem[] herb = Inventory.find(249);
		herb[0].click("Use Guam leaf -> Vial of water");
	}

	@Override
	public void run()
	{
		while (true)
		{
			sleep(50);
			if (Inventory.getAll().length == 0)
			{
				withdrawIngredients();
			}
			else if (gotIngredients())
			{
				MakePots();
			}
			else if (true) // Heb de unf pots gemaakt. > miss is dit niet nodig > eerst de bovenstaande
							// methods invullen
			{
				// Bank pots
			}
			else // geen herbs/vials in bank
			{

			}

		}

	}

}

 

Edited by Sophisticated

Share this post


Link to post
Share on other sites

Instead of checking the length of the returned array, you should get the stack size, i.e.

RSItem[] herb = Banking.find(249);
RSItem[] waterVial = Inventory.find(227);

if (herb.length > 0 && waterVial.length > 0) 
       if (herb[0].getStack() >= 14 && waterVial[0].getStack() >= 14) 
return true;
return false;

For using an item on another Clickable, just click on the item, hover the entity you want to interact with, check Game.getUpText and make sure it matches what you want, then Mouse.click(1).

 

 

  • Like 1

Share this post


Link to post
Share on other sites
4 hours ago, fegmo said:

Instead of checking the length of the returned array, you should get the stack size, i.e.

RSItem[] herb = Banking.find(249);
RSItem[] waterVial = Inventory.find(227);

if (herb.length > 0 && waterVial.length > 0) 
       if (herb[0].getStack() >= 14 && waterVial[0].getStack() >= 14) 
return true;
return false;

For using an item on another Clickable, just click on the item, hover the entity you want to interact with, check Game.getUpText and make sure it matches what you want, then Mouse.click(1).

 

 

 

 

Thanks for the reaction, got it both working now!

Share this post


Link to post
Share on other sites

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.

×