iz0n Posted January 27, 2016 Share Posted January 27, 2016 (edited) hi, im VB.Net coder , you could say expert.. and this is my very first 4 hours trying to learn it so be a little more understanding if i dont follow what you saying right away. so im trying to learn scripting with osbot. as a start, i picked up this script to start modding with and to learn from. my goal now is to make "simple" unfinished potion maker. everything seems fine, till i encountered with this little problem.. basic review: import org.osbot.rs07.api.model.Entity; import org.osbot.rs07.api.ui.RS2Widget; import org.osbot.rs07.script.Script; import java.util.concurrent.TimeUnit; import org.osbot.rs07.script.ScriptManifest; import java.awt.*; @ScriptManifest(author = "Christ1665-> simple transform by iz0n", info = "unfinished potion maker (use near a bank chest)", name = "unf pots", version = 0, logo = "") public class main extends Script { @Override public void onStart() { } private enum State { BANK, SETTING_UP, WORKING } private State getState() { if (bank.isOpen()) { return State.BANK; } if (!players.inventory.contains("Marrentill") || !players.inventory.contains("Vial of water")) { return State.SETTING_UP; } if (players.inventory.contains("Marrentill") || players.inventory.contains("Vial of water")) { return State.WORKING; } return null; } @Override public int onLoop() throws InterruptedException { switch(getState()) { case BANK: if (!players.getInventory().isEmpty()){ bank.depositAll(); } bank.withdraw("Vial of water", 14); bank.withdraw("Marrentill", 14); bank.close(); break; case SETTING_UP: Entity bank = objects.closest("Bank Chest"); bank.interact("Use"); break; case WORKING: getInventory().getItem("Marrentill").interact("Use"); getInventory().getItem("Vial of water").interact("Use"); sleep(random(700, 950)); RS2Widget w = widgets.get(309, 2); if (w != null) w.interact("Make ALL"); sleep(random(10000, 13000)); } return random(500, 800); } @Override public void onExit() { } @Override public void onPaint(Graphics2D g) { } } what im trying to do, is instead of interacting with the first item of each herb or vial of water, i want to choose to interact with the closet items to each other.. like this: normal way: what im looking for : to use any of these patterns instead of the first image so this is more like anti-pattern, any ideas how to implement it ? edited : how i would do it in vb.net create 2 lists for each item type, use any of the last 4, with the first 4 of the next item to interact with... how do i do this in here Edited January 27, 2016 by iz0n Quote Link to comment Share on other sites More sharing options...
KEVzilla Posted January 27, 2016 Share Posted January 27, 2016 (edited) I doubt you are a vb.net expert. edited : how i would do it in vb.net create 2 lists for each item type, use any of the last 4, with the first 4 of the next item to interact with... how do i do this in here You mean Java? Edited January 27, 2016 by KEVzilla Quote Link to comment Share on other sites More sharing options...
Alek Posted January 27, 2016 Share Posted January 27, 2016 Check the inventory item slot destination clips against the distance to your mouse position. We have the API link above in the navigation bar, so just search for InventorySlotDestination. Also I think you meant to say "human like pattern" instead of "anti-pattern", unless you plan on randomizing the sequence of combinations of course. Edit: how i would do it in vb.net create 2 lists for each item type, use any of the last 4, with the first 4 of the next item to interact with... You can do the same in Java as well. Quote Link to comment Share on other sites More sharing options...
Traum Posted January 29, 2016 Share Posted January 29, 2016 Hi, not very elegant, but should do the trick: public class Answer { private MethodProvider mp; public Answer() { // Step 1: find the closest marrentil slot from your mouse point. // Step 2: find the closest vial slot from the closest marrentill slot. int closestMarrentillSlot = getClosestSlotFromPoint(mp, mp.getMouse().getPosition(), (v) -> v != null && v.getName().equals("Marrentill")); Rectangle closestMarrentillSlotRectangle = InventorySlotDestination.getSlot(closestMarrentillSlot); Point closestMarrentillSlotPoint = new Point((int)closestMarrentillSlotRectangle.getCenterX(), (int)closestMarrentillSlotRectangle.getCenterY()); int closestVialSlot = getClosestSlotFromPoint(mp, closestMarrentillSlotPoint, (v) -> v != null && v.getName().equals("Vial of water")); } public static int getClosestSlotFromPoint(MethodProvider mp, Point point, Filter<Item> filter) { int slot = 0; // The closest slot. int distance = Integer.MAX_VALUE; // The smallest distance. for (int i = 0; i < 28; i++) { Item item = mp.getInventory().getItemInSlot(i); if(item == null || !filter.match(item)) continue; Rectangle rectangle = InventorySlotDestination.getSlot(i); if(rectangle == null) continue; int delta = (int)new Point((int)rectangle.getCenterX(), (int)rectangle.getCenterY()).distance(point); if(delta < distance) { slot = i; distance = delta; } } return slot; } } 1 Quote Link to comment Share on other sites More sharing options...