Jump to content
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 includes:

      Fix updater bug which was causing a bunch of issues


      TRiBot will no longer require manual hook fixes every time the RS client updates - the updater has been fully patched for objects


      Hooked login fields


      Improved the login bot


      Ability to recognize the banned/locked messages again


      Ability to read the current input for username and password fields


      If the username or password is already entered correctly, it won't be erased


      If only part of the username or password is already entered correctly, it won't be erased. The login bot will fill in what's missing.


      If there are a few invalid characters after a valid substring of your username/password, only (approximately) those invalid characters will be erased. The login bot will then proceed to fill in the missing characters.





      Coming soon:

      Skull icon fix


      Improve screen rate and responsiveness of the RS client (both regular client and LG)


      Much more
        • Thanks
        • Like
      • 20 replies
    • This release includes:

      Fix shift clicking option selecting


      Fix high paint delay settings saving


      Update prayer IDs for the quick select menu


      Remove RS3 support


      Fix hooks



      RS3 Support Removed

      The RS3 client hasn't been updated since our Old-School version of TRiBot was released, as many of you may have noticed. Keeping all of the RS3 code in the client made the client as a whole harder to maintain, larger, slower, and messier. As hardly anyone still uses the RS3 client, and since the RS3 API was hardly functioning, we made the decision to completely remove it from TRiBot.

      For the average user, this means that the client will be smaller, cleaner, and faster. Future updates will also take less work meaning there will be more frequent updates.

      If you were one of the few users still using the RS3 client, we apologize for the inconvenience. No future support for RS3 is planned. There are many other botting clients which has support for RS3, so we recommend finding an alternative if you wish to continue botting on RS3.
        • Thanks
        • Like
      • 25 replies
    • Please welcome our new developers, @JoeDezzy1, @erickho123, @Encoded, and @wastedbro.

      These members will be responsible for working on, maintaining, and improving TRiBot.

      This means that bug fixes and improvements will now come at a much faster pace! We're committed to providing users with the best botting experience possible!
        • Thanks
        • Like
      • 30 replies
    • This release includes:

      More 3rd party libraries for script writers to use


      Apache Commons Codec


      Apache Commons Collections


      Apache Commons Configuration


      Apache Commons IO


      Apache Commons Lang


      Apache Commons Math


      GSON


      Guava


      JFoenix




      Hint arrow API


      Game#getHintArrowX


      Game#getHintArrowY




      Fix player hooks including Player#getSkullIcon and Prayer#getPrayerIcon
        • Thanks
        • Like
      • 49 replies
    • This update includes:

      Fix broken hooks


      Fix login bot for the message "No reply from login server. Please wait 1 minute and try again."


      Fix bug relating to which bot tab is sent human input


      General#randomLong bug fix involving negative numbers


      Fix GE API



      Please note: There are still some issues with the login bot due to a change in the game mechanisms handling the login screen. We're working on a fix and will upload it when ready.
        • Thanks
        • Like
      • 37 replies
  • Recently Browsing   0 members

    No registered users viewing this page.

×