Jump to content
View in the app

A better way to browse. Learn more.

OSBot :: 2007 OSRS Botting

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Beginner in RS scripting, Need some help

Featured Replies

Hi all,

I've discovered OSbot recently and was intrigued about how these bots come together.  So I started watching java programming videos and eventually came across a great tutorial here on the forums. I'm still having difficulties with the API so that's why I came to you guys. If anyone would like to help me out with the following questions, that would be amazing! Here it goes:

if (bank.isOpen()) {
                if (all item_IDs in inventory are the same) {
                    bank.depositAll();
                }
                else {
                    bank.close();
                }

Is there a way to check if all item id's in the inventory are the same, or all the items for that matter, and how would I go about doing this?

 

Also, I have 14 of X item and 14 of Y item in my inventory. I need to select item X and put it on item Y. How would I make this happen?

 

I would love to hear your feedback!

just do a check if inventory.contains(itemx) if not withdraw 14 then do another check if inventory.contains(itemy) if not withdraw 14

NVM go with options below me

 

Edited by naaiz

13 minutes ago, zorxon said:

Hi all,

I've discovered OSbot recently and was intrigued about how these bots come together.  So I started watching java programming videos and eventually came across a great tutorial here on the forums. I'm still having difficulties with the API so that's why I came to you guys. If anyone would like to help me out with the following questions, that would be amazing! Here it goes:


if (bank.isOpen()) {
                if (all item_IDs in inventory are the same) {
                    bank.depositAll();
                }
                else {
                    bank.close();
                }

Is there a way to check if all item id's in the inventory are the same, or all the items for that matter, and how would I go about doing this?

 

Also, I have 14 of X item and 14 of Y item in my inventory. I need to select item X and put it on item Y. How would I make this happen?

 

I would love to hear your feedback!

Not sure if this is the best way but I would do something like:

if (invetory.isEmptyExcept(ItemID) && invetory.contains(ItemID)) {
}

 

if (getinv.contains(cake)) {

getinv.interact("use",  "1st item")

getinv.interact("use", "2nd item")

} else {

open bank

deposit all

withdraw x

withdraw y

}

 

There's many possible methods of doing this, for instance:

 

getInventory().getItem("name").interact("action");

 

So for instance, item one action would be 'Use', followed by interacting with item 2 and the second interaction string.

 

API docs here: https://osbot.org/api/

  • Author

Thanks for all the responds, I think I will be able to make it work now. Will test all this good stuff out as soon as I get home!

  • Author

Hello all, I have integrated the things above into my script but unfortunately I'm unable to test if these recommendations work. Im currently hitting the following problems with these pieces of code:

@Override
	public int onLoop() throws InterruptedException {
		
		if (inventory.isEmpty()) {
			if (bank.isOpen()) {
				
				bank.withdraw(2428, 14);
				bank.withdraw(229, 14);
				bank.close();
			}
			else {
				bank.open();	
			}
		}

		else {
			if (bank.isOpen()) {
				if (getInventory().onlyContains(123)) {
					bank.depositAll();
				}
				else {
					bank.close();
					getInventory().getItem("Vial").interact("Use");
					getInventory().getItem("Attack potion(4)").interact("Use");
				}
			}
			else {
				if (getInventory().onlyContains(123)) {
					bank.open();	
				}
				else {
					getInventory().getItem("Vial").interact("Use");
					getInventory().getItem("Attack potion(4)").interact("Use");
				}
			}
		}
		
		return random(200, 300);
	}

What I'm trying to do with the code above: Get 14 potions and 14 vials from the bank, devide them, put the results back in the bank. What happens is that it opens the bank, withdraw 14 of each item, closes the bank and then it does nothing. What am I doing wrong?

Then I tried to adjust this code to the tutorial code on the forums:

private enum State {
		DEVIDE_OUTSIDE, DEVIDE_INSIDE, BANK_POTS_INSIDE, BANK_POTS_OUTSIDE, GET_POTS_OUTSIDE, GET_POTS_INSIDE, WAIT
	};

	private State getState() {
		if (!inventory.isEmpty() && !bank.isOpen() && !getInventory().onlyContains(123))
			return State.DEVIDE_OUTSIDE;
		if (!inventory.isEmpty() && bank.isOpen() && !getInventory().onlyContains(123))
			return State.DEVIDE_INSIDE;

		if (!inventory.isEmpty() && bank.isOpen() && getInventory().onlyContains(123))
			return State.BANK_POTS_INSIDE;
		if (!inventory.isEmpty() && !bank.isOpen() && getInventory().onlyContains(123))
			return State.BANK_POTS_OUTSIDE;

		if (inventory.isEmpty() && !bank.isOpen())
			return State.GET_POTS_OUTSIDE;
		if (inventory.isEmpty() && bank.isOpen())
			return State.GET_POTS_INSIDE;
		return State.WAIT;
	}

	@Override
	public int onLoop() throws InterruptedException {
		switch (getState()) {
		case DEVIDE_OUTSIDE:
			getInventory().getItem("Vial").interact("Use");
			getInventory().getItem("Attack potion(4)").interact("Use");
			break;
		case DEVIDE_INSIDE:
			bank.close();
			getInventory().getItem("Vial").interact("Use");
			getInventory().getItem("Attack potion(4)").interact("Use");
			break;
		case BANK_POTS_OUTSIDE:
			bank.open();
			bank.depositAll();
			break;
		case BANK_POTS_INSIDE:
			bank.depositAll();
			break;
		case GET_POTS_OUTSIDE:
			bank.open();
			bank.withdraw(2428, 14);
			bank.withdraw(229, 14);
			bank.close();
			break;
		case GET_POTS_INSIDE:
			bank.withdraw(2428, 14);
			bank.withdraw(229, 14);
			bank.close();
			break;
		
		case WAIT:
			sleep(random(500, 700));
			break;
		}
		return random(2000, 3000);
	}

Now it only withdraw 14 attack potions and then it freezes the entire client and overloading my RAM memory.

Would love to hear some opinions.

Why are you trying to use a vial on an Attack potion that already has 4 doses? Also, don't interact with item IDs. Utilize the names instead. Though item IDs have the possibility to change (albeit, slight), it's just better practice to use the names instead. Since I don't know the core function you're trying to do, I can't help you with that. But here's a better banking method. A little explanation on it though. For some reason, when you're pulling multiple items out of the bank, it'll skip an item or two, and decide not to withdraw it. I have had this happen multiple times and I could not figure out why it was happening. So, it's good practice to always check to make sure you actually withdraw the item you requested to withdraw. Otherwise, you'll null out the script since you won't have that item, or items.

 

String[] requiredItems = {"Bucket of Water", "Pot of flour"};

		if (!getBank().isOpen()) {
			if (!myPlayer().isAnimating()) {
				new ConditionalSleep(5000) {
					public boolean condition() throws InterruptedException {
						return getBank().open();
					}
				}.sleep();
			}
		} else {
			getBank().depositAll();

			if (inventory.isEmpty()) {
				int bucketOfWater = (int) getBank().getAmount(requiredItems[0]);
				int potOfFlour = (int) getBank().getAmount(requiredItems[1]);

				if ((bucketOfWater != 0) && (potOfFlour != 0)) {
					while (!checkInvAmountItems(requiredItems)) {
						for (String name : requiredItems) {
							int bankAmount = (int) getBank().getAmount(name);

							if (bankAmount < 9) {
								if (bankAmount != 0) {
									getBank().withdrawAll(name);
								}
							} else {
								int invCount = (int) inventory.getAmount(name);

								if (invCount != 9) {
									getBank().withdraw(name, (9 - invCount));
								}
							}
						}
					}

					// Utilize booleans to tell the script to stop banking and do the next method
					getBank().close();
				} else {
					log("No more of the required items left.");
					// Do something to stop the script, or perform another action
				}
			}
		}
private boolean checkInvAmountItems(String[] requiredItems) {
		return inventory.getAmount(requiredItems[0]) > 0 && inventory.getAmount(requiredItems[1]) > 0 && inventory.getAmount(requiredItems[2]) > 0;
	}

 

Edited by BrainDeadGenius

  • Author
11 hours ago, BrainDeadGenius said:

Why are you trying to use a vial on an Attack potion that already has 4 doses? Also, don't interact with item IDs. Utilize the names instead. Though item IDs have the possibility to change (albeit, slight), it's just better practice to use the names instead. Since I don't know the core function you're trying to do, I can't help you with that. But here's a better banking method. A little explanation on it though. For some reason, when you're pulling multiple items out of the bank, it'll skip an item or two, and decide not to withdraw it. I have had this happen multiple times and I could not figure out why it was happening. So, it's good practice to always check to make sure you actually withdraw the item you requested to withdraw. Otherwise, you'll null out the script since you won't have that item, or items.

 

 

Mostly just for testing. I've tried your code but weird things are happening with the OSbot client and I'm not sure where the problem lies. For starters, new scripts that I put in the scripts folder don't show up in the client script selector anymore. There is just one local script I made and I have to overwrite it every time I make a new script or need to test something. Furthermore, I tried to paste your code into a new project and then save it as the previous script I made which actually works in-game. Only thing is it actually takes out the potions instead of the items that you've defined in your script. Why does this happen?

7 hours ago, zorxon said:

For starters, new scripts that I put in the scripts folder don't show up in the client script selector anymore. There is just one local script I made and I have to overwrite it every time I make a new script or need to test something. 

This tells me you're not changing the name of the script. You will have to overwrite files when you make changes to scripts. But if you don't have a file for each script you've made, then you're not changing the following information on each script.

@ScriptManifest(author = "BrainDeadGenius", info = "Unique Script Description for each script by BrainDeadGenius", name = "Unique Script Name for each script", version = 1.0, logo = "")

 

7 hours ago, zorxon said:

Furthermore, I tried to paste your code into a new project and then save it as the previous script I made which actually works in-game. Only thing is it actually takes out the potions instead of the items that you've defined in your script. Why does this happen?

Regarding the code block below, did you change the String[] to your potions? If so, then it's doing the job correctly by pulling the potions out of the bank. If not, and you left it as it is, it'll pull the Bucket of water and Pot of flour from the bank, if the bank has any.

String[] requiredItems = {"Bucket of Water", "Pot of flour"};

 

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.