sudoinit6 Posted December 19, 2016 Share Posted December 19, 2016 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? Quote Link to comment Share on other sites More sharing options...
TheGreatests Posted December 20, 2016 Share Posted December 20, 2016 Do a while loop in there, or a if loop. Example if(BarsToBuy=(int) (getInventory().get... !=null{ get item } Quote Link to comment Share on other sites More sharing options...
sudoinit6 Posted December 20, 2016 Author Share Posted December 20, 2016 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. Quote Link to comment Share on other sites More sharing options...
TheGreatests Posted December 20, 2016 Share Posted December 20, 2016 You're using getamount wrong. Quote Link to comment Share on other sites More sharing options...
sudoinit6 Posted December 20, 2016 Author Share Posted December 20, 2016 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. Quote Link to comment Share on other sites More sharing options...
sudoinit6 Posted December 20, 2016 Author Share Posted December 20, 2016 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. Quote Link to comment Share on other sites More sharing options...
TheGreatests Posted December 21, 2016 Share Posted December 21, 2016 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. Quote Link to comment Share on other sites More sharing options...
TheGreatests Posted December 21, 2016 Share Posted December 21, 2016 if you wanna teamviewer i'll help you out bro, or give me the script and i'll work on it. Quote Link to comment Share on other sites More sharing options...
sudoinit6 Posted December 21, 2016 Author Share Posted December 21, 2016 (edited) 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 December 21, 2016 by sudoinit6 Quote Link to comment Share on other sites More sharing options...
Satire Posted December 22, 2016 Share Posted December 22, 2016 (edited) 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 December 22, 2016 by lol0 1 Quote Link to comment Share on other sites More sharing options...
Mushphang Posted December 22, 2016 Share Posted December 22, 2016 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. Quote Link to comment Share on other sites More sharing options...
liverare Posted December 23, 2016 Share Posted December 23, 2016 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); } } 1 Quote Link to comment Share on other sites More sharing options...