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

  • Our picks

    • This release will:

      Add support for using custom F key bindings to switch between game tabs (Thanks @erickho123)


      Fix tab opening for "Skills" and "Kourend Tasks" (Thanks @erickho123)



      Note: If you are using LG, please restart both the RS client and TRiBot
      • 30 replies
    • This release will:

      Fix an issue where breaks would stop firing


      Fix Combat#getWildernessLevel, use dynamic search for text and cache ID for later calls


      Fix an NPE in the Combat API


      Fix Mouse#leaveGame bug where the mouse wouldn't actually leave the game screen
      • 21 replies
    • This release will:

      Add LG support for Runelite


      Fix NPCChat issues


      Fix a bug where the camera angle setter would just hold down a key for 5 seconds (the timeout)


      Slightly adjust the rotation via keys to be more accurate


      Add the ability for asynchronous camera movement via keys


      Make Camera rotation via mouse more fluid, with more antiban, and work much better in resizable mode


      Add a "Camera#setCamera" method, allowing the rotation and angle to be set in parallel


      Increase the likelihood of using the mouse for camera movements


      Add support for adjusting the camera to positionable entities (Positionable#adjustCameraTo)



      Upcoming updates:

      Improved CLI support


      Much more



      Note: If you are using LG, please restart both the RS client and TRiBot
      • 59 replies
    • This update will:

      Allow for clicking through the chat box when possible (Thanks @Todd)


      Fix Combat#selectIndex (Thanks @Encoded)


      Ensure worlds stay sorted and added a check to avoid misclicks in the in-game world hopper (Thanks @erickho123)


      Fix out-dated Options API interface indices (Thanks @Todd)



      Upcoming updates:

      Break handler bug fix


      Improved CLI support


      Much more



      Note: If you are using LG, please restart both the RS client and TRiBot
      • 12 replies
    • This release will:

      Fix login bot after today's game update (Thanks @JoeDezzy1)


      Fix latest in-game world hopping issues (Thanks @erickho123)


      Compact Settings UI and set location relative to TRiBot (Thanks @JoeDezzy1)


      Fix an older implementation of GrandExchange#getWindowState (Thanks @JoeDezzy1)


      Improve the preformance of NPCChat by only searching in certain interface parents (Thanks @JoeDezzy1)



      Upcoming updates:

      Break handler bug fix


      Improved CLI support


      LG support for RuneLite


      Much more



      Note: If you are using LG, please restart both the RS client and TRiBot
      • 16 replies
  • Recently Browsing   0 members

    No registered users viewing this page.

×