Mr Pro Pop Posted September 20, 2016 Share Posted September 20, 2016 (edited) Hello guys, I had been trying to make an inventory item drag since ages but i couldn't figure it out, So for example it moves the item from slot 1 to slot 2 or something, I tried but with no luck could not figure it out, If someone can provide me with the code and help i will be much appreciated. We need to figure this out to do an amazing script with it such as bank organizer and more stuff! All comments/posts is allowed and much appreciated! [ Please if you're not willing to help DONT post ] Best regards Mr Pro Pop. Thanks in advance! @venetox @@Explv Edited September 23, 2016 by Mr Pro Pop Quote Link to comment Share on other sites More sharing options...
Th3 Posted September 20, 2016 Share Posted September 20, 2016 (edited) threw this together quick. the @ Override is one line, osbot forums think's it's a member so it separated it public void moveInvItem(int from, int to) { if (from < 0) return; Rectangle toRec = InventorySlotDestination.getSlot(to); getMouse().continualClick(new RectangleDestination(getBot(),InventorySlotDestination.getSlot(from)), new Condition() { @[member=Override] public boolean evaluate() { if (toRec.contains(getMouse().getPosition())) return true; getMouse().move(new RectangleDestination(getBot(),toRec)); return false; } }); } example usage moveInvItem(getInventory().getSlot(ITEMID),SLOTID); Edited September 20, 2016 by Th3 3 Quote Link to comment Share on other sites More sharing options...
House Posted September 20, 2016 Share Posted September 20, 2016 (edited) threw this together quick. the @ Override is one line, osbot forums think's it's a member so it separated it public void moveInvItem(int from, int to) { if (from < 0) return; Rectangle toRec = InventorySlotDestination.getSlot(to); getMouse().continualClick(new RectangleDestination(getBot(),InventorySlotDestination.getSlot(from)), new Condition() { @[member='Override'] public boolean evaluate() { if (toRec.contains(getMouse().getPosition())) return true; getMouse().move(new RectangleDestination(getBot(),toRec)); return false; } }); } example usage moveInvItem(getInventory().getSlot(ITEMID),SLOTID); Didn't know a bunch of that stuff existed. My similar approach ghetto version: public void moveItem(int start_slot, int end_slot) { Rectangle start_slot_bounds = getSlotBounds(start_slot); Rectangle end_slot_bounds = getSlotBounds(end_slot); Mouse mouse = getMouse(); mouse.move(new RectangleDestination(getBot(), start_slot_bounds)); getBot().getMouseEventHandler().generateBotMouseEvent(MouseEvent.MOUSE_PRESSED, System.currentTimeMillis(), 0, (int) mouse.getPosition().getX(), (int) mouse.getPosition().getY(), 0, false, 0, true); mouse.move(new RectangleDestination(getBot(), end_slot_bounds)); getBot().getMouseEventHandler().generateBotMouseEvent(MouseEvent.MOUSE_RELEASED, System.currentTimeMillis(), 0, (int) mouse.getPosition().getX(), (int) mouse.getPosition().getY(), 0, false, 0, true); } public Rectangle getSlotBounds(int slot_id) { int min_x = 563; int min_y = 213; int item_dimension = 31; int gap_x = 11; int gap_y = 5; int column = (int) Math.floor(slot_id / 4); int row = slot_id % 4; int slot_y = min_y + (item_dimension * column) + (gap_y * column); int slot_x = min_x + (item_dimension * row) + (gap_x * row); return new Rectangle(slot_x, slot_y, item_dimension, item_dimension); } Edited September 20, 2016 by House 1 Quote Link to comment Share on other sites More sharing options...
Mr Pro Pop Posted September 20, 2016 Author Share Posted September 20, 2016 (edited) Thanks you @@Th3 for the help, I really appreciate! @@House i didnt understand how to does it work, wont start with me! -> Structure please! Edited September 20, 2016 by Mr Pro Pop Quote Link to comment Share on other sites More sharing options...
Mr Pro Pop Posted September 21, 2016 Author Share Posted September 21, 2016 (edited) @venetox @Explv Do you guys have any other methods to get it working or any other easiest ways ? thanks! Edited September 21, 2016 by Mr Pro Pop Quote Link to comment Share on other sites More sharing options...
Explv Posted September 22, 2016 Share Posted September 22, 2016 (edited) @venetox @Explv Do you guys have any other methods to get it working or any other easiest ways ? thanks! @@Th3's method is the same one that I use Edited September 22, 2016 by Explv Quote Link to comment Share on other sites More sharing options...
House Posted September 22, 2016 Share Posted September 22, 2016 (edited) Thanks you @@Th3 for the help, I really appreciate! @@House i didnt understand how to does it work, wont start with me! -> Structure please! err, getSlotBounds() just generates the rectangle that the item in the inventory takes up, then it just moves the mouse to the first items area, simulates a mouse button press, moves into the target area, simulates a mouse release. moveItem(0,27); Example moves from first first slot in the top left to the very bottom right. I do recommend using Th3's version though, its the same thing however it uses api methods that serve the same purpose, this means its easier to implement interrupts in the evaluate method as well. Edited September 22, 2016 by House Quote Link to comment Share on other sites More sharing options...
venetox Posted September 22, 2016 Share Posted September 22, 2016 (edited) The code I use is similar to @@Th3's, I will try to comment and explain it as best as possible. public boolean moveItemInSlot(int startSlot, final int endSlot) throws InterruptedException { if (getInventory().isItemSelected()) { // If we currently have something selected, unselect it, since we can't move items if we have something selected getInventory().deselectItem(); } return getMouse().continualClick(getInventory().getMouseDestination(startSlot), new Condition() { @ Override // Remove space here, forum likes to tag Ovveride public boolean evaluate() { getMouse().move(getInventory().getMouseDestination(endSlot), true); return getInventory().getMouseDestination(endSlot).getBoundingBox().contains(getMouse().getPosition()); } }); } So this is what it does. getMouse() Gets the instance of your mouse. getInventory().getMouseDestination(startSlot) returns the position the mouse should click to be clicking he slot you want to move from. continualClick() Moves the mouse to the specified destination (position of startSlot) and performs a left click for as long as the condition evaluates to false new Condition() creates the condition the continualClick will evaluate and until it returns true. inside evaluate() getMouse() Gets the instance of your mouse again. getInventory().getMouseDestination(slot2) gets the position the mouse should move to in order to be on endSlot move() is then used to move the mouse to endSlot getInventory().getMouseDestination(endSlot).getBoundingBox().conains(getMouse().getPosition()) is then used to check if the mouse is inside the endSlot's bounding box, if it is, then evaluate will return true and the mouse will let go of the left click and its all done, if not it will keep moving to the end slot until it is inside the bounding box. Hope this helps explain it a bit. Its a bit hard to explain, but it is fairly simple once you pull it all apart. Edited September 22, 2016 by venetox Quote Link to comment Share on other sites More sharing options...
Mr Pro Pop Posted September 23, 2016 Author Share Posted September 23, 2016 (edited) aha thanks @venetox i appreciate, Check pm! Edited September 23, 2016 by Mr Pro Pop Quote Link to comment Share on other sites More sharing options...
Valid Posted September 3, 2020 Share Posted September 3, 2020 Old topic, but for those looking for an updated solution as InventorySlotDestination is deprecated. This worked for me: public void moveInvItem(int from, int to) { if (from < 0) return; Rectangle toRec = getInventory().getSlotBoundingBox(to); RectangleDestination rectDest = new RectangleDestination(getBot(), getInventory().getSlotBoundingBox(getInventory().getSlot(from))); getMouse().continualClick(rectDest, new Condition() { public boolean evaluate() { if (toRec.contains(getMouse().getPosition())) return true; getMouse().move(new RectangleDestination(getBot(), toRec)); return false; } }); new ConditionalSleep(1200) { @Override public boolean condition() throws InterruptedException { return getInventory().getSlot(from) == to; } }.sleep(); } Quote Link to comment Share on other sites More sharing options...