Jump to content

Useful Snippets I Use


Recommended Posts

Posted

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

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