Muffins Posted April 5, 2016 Share Posted April 5, 2016 (edited) Yo, so during my late night scripting sessions, I was making a fisher for someone and the OSBot dropping method kind of sucks because it looks, well, bot like as fuck. Most players use AHK/MouseKeys and i have't seen a nice snippet for it, so me and @Isolate made one. Now, OSBot count's inventory spaces like this... Provided crudely with this picture made is MSPaint. THIS WILL DEFINE WHAT ORDER, AND WHAT INVENTORY SPACES YOU WANT TO DROP I LEFT OUT SPACES 26 AND 27 DUE TO THEM CONTAINING MY ROD/FEATHERS (FISHING) YOU CAN KEEP ALL SPACES OR TAKE OUT THE ONES YOU WISH DEPENDING ON WHAT KIND OF DROPPING YOU ARE DOING public static final int[] VERTICAL_DROP = new int[]{ 0,4,8,12,16,20,24,1,5,9,13,17,21,25,2,6,10,14,18,22,3,7,11,15,19,23}; Next, When wanting to drop, do this. Note: I am using a Task system made by @Vilius So you will have to implement it into your own code. public void process() { // Here is my order just saved in case: 0,4,8,12,16,20,24,1,5,9,13,17,21,25,2,6,10,14,18,22,3,7,11,15,19,23 for(int i : VERTICAL_DROP){ api.getInventory().interact(i, "Drop"); } Or by using a lambda provided by @Vilius VERTICAL_DROP.forEach(s -> api.getInventory().interact(s, "Drop")); And voila, it does this (or it should, I hope, I kind of suck at this coding thing) Edited April 5, 2016 by Muffins 4 Quote Link to comment Share on other sites More sharing options...
The Hero of Time Posted April 5, 2016 Share Posted April 5, 2016 that's really small and easy code ;) looks nice man! 1 Quote Link to comment Share on other sites More sharing options...
Muffins Posted April 5, 2016 Author Share Posted April 5, 2016 that's really small and easy code looks nice man! Hopefully Father @Alek can look into the OSBot dropping if he ever gets free time 1 Quote Link to comment Share on other sites More sharing options...
Vilius Posted April 5, 2016 Share Posted April 5, 2016 Looks dope. Although you can make it one line with a lambda expression. VERTICAL_DROP.forEach(s -> api.getInventory().interact(s, "Drop")); 1 Quote Link to comment Share on other sites More sharing options...
Muffins Posted April 5, 2016 Author Share Posted April 5, 2016 Looks dope. Although you can make it one line with a lambda expression. VERTICAL_DROP.forEach(s -> api.getInventory().interact(s, "Drop")); added into the Original Post 1 Quote Link to comment Share on other sites More sharing options...
iJodix Posted April 5, 2016 Share Posted April 5, 2016 Nice but if you want as fast mouse jumping when using AHK script you can use; http://osbot.org/api/org/osbot/rs07/input/mouse/ClientMouseEventHandler.html#generateBotMouseEvent-int-long-int-int-int-int-boolean-int-boolean- 1 Quote Link to comment Share on other sites More sharing options...
Muffins Posted April 5, 2016 Author Share Posted April 5, 2016 Nice but if you want as fast mouse jumping when using AHK script you can use; http://osbot.org/api/org/osbot/rs07/input/mouse/ClientMouseEventHandler.html#generateBotMouseEvent-int-long-int-int-int-int-boolean-int-boolean- Oh, ok! But I just made this because I haven't seen one posted at all Quote Link to comment Share on other sites More sharing options...
iJodix Posted April 5, 2016 Share Posted April 5, 2016 Oh, ok! But I just made this because I haven't seen one posted at all It is great snippet, much better then osbots current dropAll method really Here, have dropAllExcept so you don't have to ignore those 2 inventory slots. public void dropAllExcept(String...blacklist) { for(int i : VERTICAL_DROP){ if (getInventory().getItemInSlot(i) != null && getInventory().getItemInSlot(i).hasAction("Drop") && !getInventory().getItemInSlot(i).getName().equals(blacklist)) { getInventory().interact(i, "Drop"); } } } 3 Quote Link to comment Share on other sites More sharing options...
Muffins Posted April 5, 2016 Author Share Posted April 5, 2016 It is great snippet, much better then osbots current dropAll method really Here, have dropAllExcept so you don't have to ignore those 2 inventory slots. public void dropAllExcept(String...blacklist) { for(int i : VERTICAL_DROP){ if (getInventory().getItemInSlot(i) != null && getInventory().getItemInSlot(i).hasAction("Drop") && !getInventory().getItemInSlot(i).getName().equals(blacklist)) { getInventory().interact(i, "Drop"); } } } pls sir i am just a lowlife skriptor 1 but foreal, I had a blacklist before but i removed it while editing my methods im pretty sure and just cbf to add it back since it was late Quote Link to comment Share on other sites More sharing options...
GaetanoH Posted April 5, 2016 Share Posted April 5, 2016 Very nice, might use it in future scripts dude! Quote Link to comment Share on other sites More sharing options...
liverare Posted April 5, 2016 Share Posted April 5, 2016 (edited) pls sir i am just a lowlife skriptor 1 but foreal, I had a blacklist before but i removed it while editing my methods im pretty sure and just cbf to add it back since it was late Don't use that code. At no point is the Item defined, so he's having to constantly retrieve a single item from the Inventory class multiple times. This is very inefficient. The parameters are also a limitation too. There may be other conditions you wish to set before dropping anything. I'd go for something like this: // From int[] to Integer[] because Arrays.asList(Object) doesn't work with primitive type arrays public static final Integer[] VERTICAL_DROP = { 0, 4, 8, 12, 16, 20, 24, 1, 5, 9, 13, 17, 21, 25, 2, 6, 10, 14, 18, 22, 3, 7, 11, 15, 19, 23 }; public static final List<Integer> VERTICAL_DROP_AS_LIST = Arrays.asList(VERTICAL_DROP); public void dropAll(Predicate<Item> filter) { VERTICAL_DROP_AS_LIST.forEach((index) -> { // Acquire item once, store it as a variable Item item = getInventory().getItemInSlot(index); // Validate the item before interacting with it, also only use filter if one exists if (item != null && item.hasAction("Drop") && (filter != null && filter.test(item))) { item.interact("Drop"); /* * Item#interact(String...) returns a boolean, which you could * wrap in a selector (IF) for better handling */ } }); } public void dropFish() { // Lambda this shit the fuck up! dropAll((item) -> item.getName().equals("Trout") && !item.isNote()); } I haven't actually tested this, but it should work. If you want to go full autist you could have the Integer array explicitly defined within the parameters of the Arrays#asList(Object) method. This would just mean you wouldn't need to define VERTICAL_DROP as a global constant. It's justified too, since VERTICAL_DROP is only ever likely to be referenced once. However having VERTICAL_DROP as mostly dead code isn't going to rip holes in time and space. Edited April 5, 2016 by liverare 1 Quote Link to comment Share on other sites More sharing options...
Muffins Posted April 5, 2016 Author Share Posted April 5, 2016 Don't use that code. At no point is the Item defined, so he's having to constantly retrieve a single item from the Inventory class multiple times. This is very inefficient. The parameters are also a limitation too. There may be other conditions you wish to set before dropping anything. I'd go for something like this: // From int[] to Integer[] because Arrays.asList(Object) doesn't work with primitive type arrays public static final Integer[] VERTICAL_DROP = { 0, 4, 8, 12, 16, 20, 24, 1, 5, 9, 13, 17, 21, 25, 2, 6, 10, 14, 18, 22, 3, 7, 11, 15, 19, 23 }; public static final List<Integer> VERTICAL_DROP_AS_LIST = Arrays.asList(VERTICAL_DROP); public void dropAll(Predicate<Item> filter) { VERTICAL_DROP_AS_LIST.forEach((index) -> { // Acquire item once, store it as a variable Item item = getInventory().getItemInSlot(index); // Validate the item before interacting with it, also only use filter if one exists if (item != null && item.hasAction("Drop") && (filter != null && filter.test(item))) { item.interact("Drop"); /* * Item#interact(String...) returns a boolean, which you could * wrap in a selector (IF) for better handling */ } }); } public void dropFish() { // Lambda this shit the fuck up! dropAll((item) -> item.getName().equals("Trout") && !item.isNote()); } I haven't actually tested this, but it should work. If you want to go full autist you could have the Integer array explicitly defined within the parameters of the Arrays#asList(Object) method. This would just mean you wouldn't need to define VERTICAL_DROP as a global constant. It's justified too, since VERTICAL_DROP is only ever likely to be referenced once. However having VERTICAL_DROP as mostly dead code isn't going to rip holes in time and space. Thank you father Quote Link to comment Share on other sites More sharing options...
Botre Posted April 5, 2016 Share Posted April 5, 2016 Don't use that code. At no point is the Item defined, so he's having to constantly retrieve a single item from the Inventory class multiple times. This is very inefficient. No. I'm pretty sure ItemContainer's interact(slot, action) method does try to define an Item internally, probably similarly to the way you do it. So he should be fine ^^ PS: here's an old snippet of mine if you're looking for alternative patterns :p http://osbot.org/forum/topic/68138-using-certain-slots-help/?p=750312 1 Quote Link to comment Share on other sites More sharing options...
liverare Posted April 5, 2016 Share Posted April 5, 2016 No. I'm pretty sure ItemContainer's interact(slot, action) method does try to define an Item internally, probably similarly to the way you do it. So he should be fine ^^ Well that's new to me. Quote Link to comment Share on other sites More sharing options...
The Hero of Time Posted April 5, 2016 Share Posted April 5, 2016 (edited) It is great snippet, much better then osbots current dropAll method really Here, have dropAllExcept so you don't have to ignore those 2 inventory slots. public void dropAllExcept(String...blacklist) { for(int i : VERTICAL_DROP){ if (getInventory().getItemInSlot(i) != null && getInventory().getItemInSlot(i).hasAction("Drop") && !getInventory().getItemInSlot(i).getName().equals(blacklist)) { getInventory().interact(i, "Drop"); } } } Tested and doesn't work, still drops the blacklisted item, you try to check on the entire list, not on an item in the list Edited April 5, 2016 by The Hero of Time Quote Link to comment Share on other sites More sharing options...