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.

Want to buy as many gold bars as I can...

Featured Replies

Assuming the GE is open and declared private int barsToBuy;

 

 

 

barsToBuy = (int) (getInventory().getAmount("Coins") / 100);

getGrandExchange().buyItem(2357, "Gold bar", 100, barsToBuy);

 

Why does this only buy one bar?

Do a while loop in there, or a if loop.

Example

if(BarsToBuy=(int) (getInventory().get...  !=null{

get item

}

  • Author

Do a while loop in there, or a if loop.

Example

if(BarsToBuy=(int) (getInventory().get...  !=null{

get item

}

 

 

Wouldn't that buy them one at a time? I am buying them on the exchange, that seems terribly inefficient. 

 

It is also possible I am misunderstanding you.

  • Author

You're using getamount wrong.

 

 

How so?

 

Currently I have it set up such that I use it that way and if it returns <= a number it buys x gold bars and if it return > that number it buys y gold bars and that is working properly.

  • Author

You're using getamount wrong.

 

 

Looking into it you must be right. According to the docs item.getAmount(int) returns an int but in my script the way I am using it I am forced to cast it as an int because it is looking for a long....

 

And advice would be greatly appreciated here.

Try this

int barsToBuy;

barsToBuy = getInventory().getAmount("Coins") / 100);

 


Honestly bro, I am pretty new to this all over again. im trying to figure out how to calculate all players around me and if the players are more then 3, to hop worlds.

if you wanna teamviewer i'll help you out bro, or give me the script and i'll work on it.

  • Author

if you wanna teamviewer i'll help you out bro, or give me the script and i'll work on it.

 

 

Thanks for the offer, obviously I am pretty new too but every day I get a little better. In case someone else is trying to do the same thing and can't figure it out here is what ended up working (the -1 was to ensure there is enough money to buy a mould on the first trip):

 

Item coins = getInventory().getItem("Coins");
            barsToBuy = ((coins.getAmount() / 100)-1);
            getGrandExchange().buyItem(2357, "Gold bar", 100, (int) barsToBuy);
 
 
Your solution was close but getItem returns a long, not an int, so it needs to be cast.

Edited by sudoinit6

Assuming the GE is open and declared private int barsToBuy;

 

 

 

barsToBuy = (int) (getInventory().getAmount("Coins") / 100);

getGrandExchange().buyItem(2357, "Gold bar", 100, barsToBuy);

 

Why does this only buy one bar?

 

why don't you just get the amount of coins in your inventory. Then get the price of the ore from RSbuddy, then * the price by amount of ores you want, then check to see if you have enough coins? 

 

Or you could do it the opposite way and calculate how many ores u can get with the amount of money you have. 

Make sure barsTobuy is getting the right value. It seems like it isn't.  Debug it step by step to see what's going on. 

 

I cbf writing it all up normally so I hope you understand.

getinv = getInventory etc...

 

 

long  coins =  getinv().getamount("Coins");

 

get price of item

 

oresToBuy = (int)coins/price of item; which would = the amount u can get, sum it down to an int to get that value.

You can use this code to get the price of the item

 

This code is from another user, you can find it somewhere ( I forgot where).

public class PriceHandler {


    /**
     * The URL of the API endpoint.
     */


    public static HashMap<Integer, Integer> cache = new HashMap<Integer, Integer>();


    public static String getData(int itemID) {
        try {
            StringBuilder sb = new StringBuilder("https://api.rsbuddy.com/grandExchange?a=guidePrice&i=");
            sb.append(String.valueOf(itemID));
            InputStream inputStream = new URL(sb.toString()).openStream();
            InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
            BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
            String line;
            while ((line = bufferedReader.readLine()) != null) {
                if (line.contains("{")) {
                    sb = new StringBuilder(line);
                    //Remove { and }
                    sb.deleteCharAt(0);
                    //sb.deleteCharAt((line.length() - 1));
                    return sb.toString();
                }
            }
        }
        catch (Exception e) {
            return e.getMessage();
        }
        return null;
    }


    public static String[] parseData(String data) {
        ArrayList<String> holder = new ArrayList<String>();
        String[] parts = data.split(","); //Now we have strings in format "x":y
        for (String s : parts) {
            s = s.replace("\"", ""); //Remove " - now in format x:y
            holder.add(s.split(":")[1]); //Extract y from format x:y
        }
        String[] ret = new String[holder.size()];
        return holder.toArray(ret);
    }


    public static int getPrice(int itemID) {
        if (itemID == 995) return 1;


        if (cache.containsKey(itemID)) {
            return cache.get(itemID);
        }
        String[] data = parseData(getData(itemID));
        int price = Integer.valueOf(data[0]);
        cache.put(itemID, price);
        return price;
    }


}

 

Assuming the GE is open and declared private int barsToBuy;

 

 

 

barsToBuy = (int) (getInventory().getAmount("Coins") / 100);

getGrandExchange().buyItem(2357, "Gold bar", 100, barsToBuy);

 

Why does this only buy one bar?

 

Edited by lol0

 

Thanks for the offer, obviously I am pretty new too but every day I get a little better. In case someone else is trying to do the same thing and can't figure it out here is what ended up working (the -1 was to ensure there is enough money to buy a mould on the first trip):

 

Item coins = getInventory().getItem("Coins");
            barsToBuy = ((coins.getAmount() / 100)-1);
            getGrandExchange().buyItem(2357, "Gold bar", 100, (int) barsToBuy);
 
 
Your solution was close but getItem returns a long, not an int, so it needs to be cast.

 

 

If you still haven't found your solution add a log message in there to help you debug the issue.

try throwing a log("Amount of gold bars to buy: " + barsToBuy); in between the the bars to buy and and grand exchange. Also maybe ttry this code instead of getGrandExchange()

grandExchange.buyItem(2357, "Gold bar", 100, (int) barsToBuy);

might have to code in opening the GE first (not 100% sure) but run it with that and see what it gives ya.

Perhaps something like:
 

int coinId = 995;
		int goldBarPrice = 100;
		int currentWealth = 0;
		int affordableQuantity = 0;
		Item coins = inventory.getItem(coinId);
		
		if (coins != null) {
			
			currentWealth = coins.getAmount();
			
			affordableQuantity = (int) ((double) currentWealth / (double) goldBarPrice);
			
			if (affordableQuantity > 0) {
				
				grandExchange.buyItem(coinId, "Gold bars", goldBarPrice, affordableQuantity);
			}
		}

Create an account or sign in to comment

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.