Jump to content

Useful Snippets I Use


venetox

Recommended Posts

Hi,

I will keep this thread updated with snippets of code I find useful. If the code is not mine I will tag/link/name creator.

/**
     * Moves the item found by itemName to the tab defined by tabNumber in the bank.
     * @param itemName The String itemName of the item.
     * @param tabNumber The tab number starting from 0, 0 is the global tab, 1 is the first tab etc.
     * @return Returns true if success, false if failed at any point.
     */
    public boolean moveItemToTab(String itemName, int tabNumber)
    {
    	RS2Widget tabWidget = getWidgets().get(12, 10, tabNumber); // Here we get the widget that refers to the tab we want to send it to inside the bank.
    	Item item = getBank().getItem(itemName); // Here we get the instance of the item we want to move. (Item must be in bank)
    	if(tabWidget != null && item != null)
    	{
    		Rectangle tabClickRectangle = tabWidget.getBounds(); // Here we get the bounding box for the widget (spot we must click)
    		RectangleDestination tabDestination = new RectangleDestination(bot, tabClickRectangle); // Here we make that bounding box into a destination the mouse can use
    		
    		item.hover(); // Here we move the mouse to the item we want to move.
    		
    		Rectangle currentPos = new Rectangle((int) getMouse().getPosition().getX(), (int) getMouse().getPosition().getY(), 1, 1); // Here we get the mouses current position after moving to the item.
    		RectangleDestination currentDestination = new RectangleDestination(bot, currentPos); // Create destination for the current position.
    		
    		return getMouse().continualClick(currentDestination, new Condition() { // Here we move from the current positon, to the tab's destination.
    			public boolean evaluate() {
    				getMouse().move(tabDestination, true);
    				return tabClickRectangle.getBounds().contains(getMouse().getPosition());
    			}
    		});
    	}
    	else
    		return false;
    	
    	
    }
  • Like 5
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...