Jack Posted May 19, 2014 Share Posted May 19, 2014 (edited) import org.osbot.script.Script; import org.osbot.script.rs2.ui.Inventory; public class Snipets { Script script; public boolean drinkBestPot(String type) throws Exception{ Inventory inv = script.client.getInventory(); String potName; if(inv.contains("Extreme "+type+" (1)")) potName = "Extreme "+type+" (1)"; else if(inv.contains("Extreme "+type+" (2)")) potName = "Extreme "+type+" (2)"; else if(inv.contains("Extreme "+type+" (3)")) potName = "Extreme "+type+" (3)"; else if(inv.contains("Extreme "+type+" (4)")) potName = "Extreme "+type+" (4)"; else if(inv.contains("Super "+type+" (1)")) potName = "Super "+type+" (1)"; else if(inv.contains("Super "+type+" (2)")) potName = "Super "+type+" (2)"; else if(inv.contains("Super "+type+" (3)")) potName = "Super "+type+" (3)"; else if(inv.contains("Super "+type+" (4)")) potName = "Super "+type+" (4)"; else if(inv.contains(type+" potion (1)")) potName = type+" potion (1)"; else if(inv.contains(type+" potion (2)")) potName = type+" potion (2)"; else if(inv.contains(type+" potion (3)")) potName = type+" potion (3)"; else if(inv.contains(type+" potion (4)")) potName = type+" potion (4)"; else return false; return inv.interactWithName(potName, "Drink"); } } Because code optimization is for pussies... Wow people thought I was serious Edited May 21, 2014 by Jack Link to comment Share on other sites More sharing options...
Volta Posted May 19, 2014 Share Posted May 19, 2014 If Else Return Link to comment Share on other sites More sharing options...
liverare Posted May 19, 2014 Share Posted May 19, 2014 (edited) XD This made my day! There are 12 selectors calling the #contains(...) method, which means there's a maximum of (12 * 28 = 336) iterations. All my fucking lel. Edited May 19, 2014 by liverare 2 Link to comment Share on other sites More sharing options...
Kenneh Posted May 19, 2014 Share Posted May 19, 2014 I really hope this is a joke. You spelled snippets wrong, you have a null script instance and the code is just laughable. PS: If something looks overly complicated, there's probably an easier way to do it. 1 Link to comment Share on other sites More sharing options...
Swizzbeat Posted May 19, 2014 Share Posted May 19, 2014 Didn't you make a thread a little bit ago asking for a project to do for scholar rank...? 3 Link to comment Share on other sites More sharing options...
Reid Posted May 20, 2014 Share Posted May 20, 2014 what the fuck Link to comment Share on other sites More sharing options...
Dog_ Posted May 20, 2014 Share Posted May 20, 2014 This is the best code I've seen in months. 2 Link to comment Share on other sites More sharing options...
NotoriousPP Posted May 20, 2014 Share Posted May 20, 2014 This is almost as bad as: int j=0; for (int i=0; i < a.length; ++i) { j++; } System.out.println("array size=" + j); 3 Link to comment Share on other sites More sharing options...
Guest Apogee Posted May 21, 2014 Share Posted May 21, 2014 if (integer(1) =!=!= -73 THEN DO) { log("I'm incredible with scripting."); sleep(completelyrandom.superrandom,even.(40, 69); } Link to comment Share on other sites More sharing options...
Jack Posted May 21, 2014 Author Share Posted May 21, 2014 if (integer(1) =!=!= -73 THEN DO) { log("I'm incredible with scripting."); sleep(completelyrandom.superrandom,even.(40, 69); } This is almost as bad as: int j=0; for (int i=0; i < a.length; ++i) { j++; } System.out.println("array size=" + j); This is the best code I've seen in months. what the fuck Didn't you make a thread a little bit ago asking for a project to do for scholar rank...? I really hope this is a joke. You spelled snippets wrong, you have a null script instance and the code is just laughable. PS: If something looks overly complicated, there's probably an easier way to do it. XD This made my day! There are 12 selectors calling the #contains(...) method, which means there's a maximum of (12 * 28 = 336) iterations. All my fucking lel. If Else Return This is a joke... "Because code optimization is for pussies..." Link to comment Share on other sites More sharing options...
Dog_ Posted May 21, 2014 Share Posted May 21, 2014 This is a joke... "Because code optimization is for pussies..." This is the wrong place to post jokes. Link to comment Share on other sites More sharing options...
Jack Posted May 21, 2014 Author Share Posted May 21, 2014 This is the wrong place to post jokes. Its completely functional code :P Link to comment Share on other sites More sharing options...
Kenneh Posted May 21, 2014 Share Posted May 21, 2014 Its completely functional code No it's not. Your script instance will always be null. You'd have to instantiate the class to use it since the method is public and not static. It WOULD be perfectly functional if you passed and assigned the script instance in the class constructor. Link to comment Share on other sites More sharing options...
liverare Posted May 23, 2014 Share Posted May 23, 2014 Okay, I'll be the first to post some kind of solution... public static Item getBestPotion(Inventory inventory, Skill skill) { String skillToLowercase = skill.name().toLowerCase(); String[] potionNames = { "Extreme " + skillToLowercase, // Extreme attack "Super " + skillToLowercase, // Super attack (skill.name().charAt(0) + skill.name().substring(1).toLowerCase()) + " potion" // Attack potion }; return inventory.getItemForNameThatContains(potionNames); } public static boolean drinkBestPotion(Inventory inventory, Skill skill) throws InterruptedException { Item bestPotion = getBestPotion(inventory, skill); return bestPotion != null && inventory.interactWithId(bestPotion.getId(), "Drink"); } 1 Link to comment Share on other sites More sharing options...
Kenneh Posted May 26, 2014 Share Posted May 26, 2014 Okay, I'll be the first to post some kind of solution... public static Item getBestPotion(Inventory inventory, Skill skill) { String skillToLowercase = skill.name().toLowerCase(); String[] potionNames = { "Extreme " + skillToLowercase, // Extreme attack "Super " + skillToLowercase, // Super attack (skill.name().charAt(0) + skill.name().substring(1).toLowerCase()) + " potion" // Attack potion }; return inventory.getItemForNameThatContains(potionNames); } public static boolean drinkBestPotion(Inventory inventory, Skill skill) throws InterruptedException { Item bestPotion = getBestPotion(inventory, skill); return bestPotion != null && inventory.interactWithId(bestPotion.getId(), "Drink"); } I'll post another way in a bit. Link to comment Share on other sites More sharing options...