Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
Sign in to follow this  
shaiguy

How do I equip items?

Recommended Posts

Been trying for awhile and can't figure it out.

Here's what I'm trying: 

 

    public void equipItems(RSItem[] item)
    {        
        Inventory.open();
        println(item[0].getID());
        println("trying to wear glory");
        item[0].click("Wear");    
    }

Share this post


Link to post
Share on other sites

Essentially you want to create an RSItem[]. Let's call it glory.

RSItem[] glory = Inventory.find(GLORY_IDS/NAME); // Can either use item ID's or do it by name
  
  if (glory.length > 0) {
  	if (glory[0].click("Use") {
      waitItemInteraction() // It's good to put a small, random wait between item interactions.
        glory[0].click("Equip");
    	}
        // Then, it would be best to add a wait condition here, that waits to make sure you have a glory equipped before continuing
    }

 

Share this post


Link to post
Share on other sites
Posted (edited)
 // Equip item
	    public static void equipGlory(int id) {
	    	RSItem[] glory = Inventory.find(id);
			if (glory.length > 0) {
				if (Clicking.click("Equip", glory[0])) {
					Antiban.waitItemInteractionDelay();
					Timing.waitCondition(new Condition() {
						@Override
						public boolean active() {
							General.sleep(100, 200);
							return Utils.isEquipped(id);
						}
					}, General.random(1500, 2500));
				}
			}
	    }
 //Check if items are equipped
	    public static boolean isEquipped(int id) {
	    	return Equipment.isEquipped(id);
	    }

 

Edited by boe123
edit
  • Like 1

Share this post


Link to post
Share on other sites
7 minutes ago, boe123 said:
 // Equip item
	    public static void equipGlory(int id) {
	    	RSItem[] glory = Inventory.find(id);
			if (glory.length > 0) {
				if (Clicking.click("Equip", glory[0])) {
					Antiban.waitItemInteractionDelay();
					Timing.waitCondition(new Condition() {
						@Override
						public boolean active() {
							General.sleep(100, 200);
							return Utils.isEquipped(id);
						}
					}, General.random(1500, 2500));
				}
			}
	    }

 

Antiban didn't have an import for me. But would this code work just as good?

 

    public void equipItems(RSItem[] item)
    {        
        Inventory.open();
        if (item.length > 0) {
            if (Clicking.click(Inventory.find(item[0].getID())))
            {
                Timing.waitCondition(new Condition() {
                    @Override
                    public boolean active() {
                        General.sleep(100, 200);
                        return Equipment.isEquipped(item[0].getID());
                    }
                }, General.random(1500, 2500));
            }
        }
    }

Share this post


Link to post
Share on other sites
Posted (edited)
16 minutes ago, shaiguy said:

Antiban didn't have an import for me. But would this code work just as good?

 

    public void equipItems(RSItem[] item)
    {        
        Inventory.open();
        if (item.length > 0) {
            if (Clicking.click(Inventory.find(item[0].getID())))
            {
                Timing.waitCondition(new Condition() {
                    @Override
                    public boolean active() {
                        General.sleep(100, 200);
                        return Equipment.isEquipped(item[0].getID());
                    }
                }, General.random(1500, 2500));
            }
        }
    }

Actually that will not work, it will return a out of index error when you check the inventory. You will want to do that outside of the method

Edited by boe123
editr
  • Like 1

Share this post


Link to post
Share on other sites
Just now, shaiguy said:

when would that return a return out of index error? 

I ran it and it worked. 

So let's find it doesn't find any items in your inventory of that id. It will return NULL and have no idea what to click which will throw an error and break the script. When dealing with objects, it is best to search for the object first.

RSITEM[] item = Inventory.find(id)

Then check if an item is found and it's not NULL

if (item.length >0 (We found something))

Then you know for sure the item was found and you can use it

Clicking.click("Equip", item);

 

Share this post


Link to post
Share on other sites
4 minutes ago, boe123 said:

So let's find it doesn't find any items in your inventory of that id. It will return NULL and have no idea what to click which will throw an error and break the script. When dealing with objects, it is best to search for the object first.

RSITEM[] item = Inventory.find(id)

Then check if an item is found and it's not NULL

if (item.length >0 (We found something))

Then you know for sure the item was found and you can use it

Clicking.click("Equip", item);

 

I see, so something like this?

        if (item.length > 0) {
            if (Inventory.find(item[0].getID()) != null)
            {
                Clicking.click(Inventory.find(item[0].getID()));

Share this post


Link to post
Share on other sites
Just now, shaiguy said:

I see, so something like this?

        if (item.length > 0) {
            if (Inventory.find(item[0].getID()) != null)
            {
                Clicking.click(Inventory.find(item[0].getID()));

Not exactly, you are not using the Inventory.find method correctly. That will return an object of the id if it exists. 

Clicking.click(Inventory.find(item[0].getID())  will attempt to click on object of an array you already specified the id's in and you are already using the getID method. This can work only if Inventory.find always returns something.

// Equip item
	    public static void equipGlory() {
	    	RSItem[] glory = Inventory.find(gloryID); // We want to look in inventory for all items with gloryID
			if (glory.length > 0) { // We want to check the glory array to see if we have found any items of gloryID
				if (Clicking.click("Equip", glory[0])) { // We want to click the first element found matching gloryID
					Timing.waitCondition(new Condition() {
						@Override
						public boolean active() {
							General.sleep(100, 200);
							return Equipment.isEquipped(gloryID);
						}
					}, General.random(1500, 2500));
				}
			}
	    }

I've given a better description on this code so it might help

Share this post


Link to post
Share on other sites
8 minutes ago, boe123 said:

Not exactly, you are not using the Inventory.find method correctly. That will return an object of the id if it exists. 

Clicking.click(Inventory.find(item[0].getID())  will attempt to click on object of an array you already specified the id's in and you are already using the getID method. This can work only if Inventory.find always returns something.

// Equip item
	    public static void equipGlory() {
	    	RSItem[] glory = Inventory.find(gloryID); // We want to look in inventory for all items with gloryID
			if (glory.length > 0) { // We want to check the glory array to see if we have found any items of gloryID
				if (Clicking.click("Equip", glory[0])) { // We want to click the first element found matching gloryID
					Timing.waitCondition(new Condition() {
						@Override
						public boolean active() {
							General.sleep(100, 200);
							return Equipment.isEquipped(gloryID);
						}
					}, General.random(1500, 2500));
				}
			}
	    }

I've given a better description on this code so it might help

if you know the object exists would it work well?

 

I'm using the function I made like this:

private final int [] GLORY = {11978, 11976, 1712, 1710, 1708, 1706 };

    private boolean checkGlory()
    {
        RSItem[] glories = Equipment.find(GLORY);
        while(true)
        {
            if(glories.length == 0) 
            {
                if(Banking.isInBank())
                {
                    Equipment.remove("Amulet of Glory");
                    Banking.openBank();
                    Banking.deposit(1, "Amulet of Glory");
                    RSItem[] test = Banking.find(GLORY);
                    Banking.withdrawItem (test[0],1);
                    Banking.close();
                    equipItems(test);
                    return false;
                }
                else
                {
                    WebWalking.walkToBank();
                }
            }
        }
    }

Share this post


Link to post
Share on other sites
7 minutes ago, shaiguy said:

if you know the object exists would it work well?

 

I'm using the function I made like this:

private final int [] GLORY = {11978, 11976, 1712, 1710, 1708, 1706 };

    private boolean checkGlory()
    {
        RSItem[] glories = Equipment.find(GLORY);
        while(true)
        {
            if(glories.length == 0) 
            {
                if(Banking.isInBank())
                {
                    Equipment.remove("Amulet of Glory");
                    Banking.openBank();
                    Banking.deposit(1, "Amulet of Glory");
                    RSItem[] test = Banking.find(GLORY);
                    Banking.withdrawItem (test[0],1);
                    Banking.close();
                    equipItems(test);
                    return false;
                }
                else
                {
                    WebWalking.walkToBank();
                }
            }
        }
    }

You shouldn't write code with that mindset. Write for the worst case scenario and you'll run into a LOT less issues.

There's a lot wrong with your code anyway. You've made a boolean that will never return anything of value and you're relying on everything working in succession to equip the glory. For example, if banking.close fails because of lag or say you fail to withdraw the item, you're going to try equip something that doesn't exist and your script will break.

  • Like 1

Share this post


Link to post
Share on other sites
3 minutes ago, HeyImJamie said:

You shouldn't write code with that mindset. Write for the worst case scenario and you'll run into a LOT less issues.

There's a lot wrong with your code anyway. You've made a boolean that will never return anything of value and you're relying on everything working in succession to equip the glory. For example, if banking.close fails because of lag or say you fail to withdraw the item, you're going to try equip something that doesn't exist and your script will break.

I see. thank you that makes sense. I will make check statements for situations like these. 

Share this post


Link to post
Share on other sites
On 18-3-2018 at 9:05 PM, boe123 said:

Not exactly, you are not using the Inventory.find method correctly. That will return an object of the id if it exists. 

Clicking.click(Inventory.find(item[0].getID())  will attempt to click on object of an array you already specified the id's in and you are already using the getID method. This can work only if Inventory.find always returns something.

// Equip item
	    public static void equipGlory() {
	    	RSItem[] glory = Inventory.find(gloryID); // We want to look in inventory for all items with gloryID
			if (glory.length > 0) { // We want to check the glory array to see if we have found any items of gloryID
				if (Clicking.click("Equip", glory[0])) { // We want to click the first element found matching gloryID
					Timing.waitCondition(new Condition() {
						@Override
						public boolean active() {
							General.sleep(100, 200);
							return Equipment.isEquipped(gloryID);
						}
					}, General.random(1500, 2500));
				}
			}
	    }

I've given a better description on this code so it might help

By using this code I get the next errors:

Multiple markers at this line
    - void[] is an invalid type
    - Illegal modifier for parameter equipGlory; only final is permitted
    - Syntax error, insert ";" to complete LocalVariableDeclarationStatement
    - Syntax error, insert "[ ]" to complete Dimension
    - Syntax error on token "equipGlory", AnnotationName expected after 

How can I fix this?

Share this post


Link to post
Share on other sites
42 minutes ago, Wildstrains said:

By using this code I get the next errors:

Multiple markers at this line
    - void[] is an invalid type
    - Illegal modifier for parameter equipGlory; only final is permitted
    - Syntax error, insert ";" to complete LocalVariableDeclarationStatement
    - Syntax error, insert "[ ]" to complete Dimension
    - Syntax error on token "equipGlory", AnnotationName expected after 

How can I fix this?

 

 

It sounds like you have inserted his code inside another method.

 

IlpPxED.png

Share this post


Link to post
Share on other sites
54 minutes ago, Wildstrains said:

Yes that's right, did it in public void run()
Should I do it in front of the void run?

It doesn't matter if it's written above or below the run() method. It will execute whenever you call it.

I strongly recommend learning some Java before attempting to write a script.

https://docs.oracle.com/javase/tutorial/

Share this post


Link to post
Share on other sites

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
Sign in to follow this  

  • Our picks

    • This release will:

      Fix LG for both OSBuddy and RuneLite


      Fix issue where the resizable client isn't able to be made smaller (Thanks @JoeDezzy1)


      Fix detection of the logout game tab when resizable mode and side panels are enabled (Thanks @JoeDezzy1)


      Add initial support for Sentry to allow us to identify and easily debug exceptions happening with all TRiBot users


      Add methods to determine if the bank is actually loaded, and not just the overarching interface (Thanks @wastedbro)



      Upcoming updates:

      Improved CLI support


      Full Sentry support


      Much more
      • 51 replies
    • This release will:

      Fix NPE in Camera API (Thanks @wastedbro)


      Update deposit box interface ids (Thanks @Encoded)


      Add various bank methods (Thanks @wastedbro)


      Banking#getWithdrawXQuantity


      Banking#getDefaultWithdrawQuantity


      Banking#arePlaceholdersOn




      Fix resizeable minimap bug (Thanks @wastedbro)


      Remove Java 8 requirement


      Please note: TRiBot is not yet fully compatible with Java 10+




      Fix the break handler issues by ensuring the break handler thread never gets paused


      Fix broken settings hooks



      Upcoming updates:

      Improved CLI support


      Much more



      Note: If you are using LG, please restart both the RS client and TRiBot
      • 68 replies
    • This release will:

      Add support for using custom F key bindings to switch between game tabs (Thanks @erickho123)


      Fix tab opening for "Skills" and "Kourend Tasks" (Thanks @erickho123)



      Note: If you are using LG, please restart both the RS client and TRiBot
      • 34 replies
    • This release will:

      Fix an issue where breaks would stop firing


      Fix Combat#getWildernessLevel, use dynamic search for text and cache ID for later calls


      Fix an NPE in the Combat API


      Fix Mouse#leaveGame bug where the mouse wouldn't actually leave the game screen
      • 21 replies
    • This release will:

      Add LG support for Runelite


      Fix NPCChat issues


      Fix a bug where the camera angle setter would just hold down a key for 5 seconds (the timeout)


      Slightly adjust the rotation via keys to be more accurate


      Add the ability for asynchronous camera movement via keys


      Make Camera rotation via mouse more fluid, with more antiban, and work much better in resizable mode


      Add a "Camera#setCamera" method, allowing the rotation and angle to be set in parallel


      Increase the likelihood of using the mouse for camera movements


      Add support for adjusting the camera to positionable entities (Positionable#adjustCameraTo)



      Upcoming updates:

      Improved CLI support


      Much more



      Note: If you are using LG, please restart both the RS client and TRiBot
      • 59 replies
  • Recently Browsing   0 members

    No registered users viewing this page.

×