Jump to content

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


sudoinit6

Recommended Posts

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
Link to comment
Share on other sites

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
  • Like 1
Link to comment
Share on other sites

 

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.

Link to comment
Share on other sites

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);
			}
		}
  • Like 1
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.

  • Recently Browsing   0 members

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