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
 // 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 2

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
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

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.

Sign in to follow this  

  • Our picks

    • This release will:

      Fix prayers and world hopper API (Thanks @JoeDezzy1 and @erickho123)


      Improve banking API (Thanks @Encoded)


      Adds methods for returning and using Java Lists, rather than arrays


      Slightly randomizes some hardcoded behaviour


      Removes sleeps from waitConditions; the efficiency saving potential is negligible in these use-cases, therefore cleaner code is preferable


      Other back-end improvements





      Note: If you are using LG, please restart both the RS client and TRiBot.
        • Sad
        • Haha
        • Thanks
        • Like
      • 61 replies
    • This release will:

      Add new internal framework for capturing exceptions


      Fix issue with not selecting the last column in world hopper (Thanks @Todd)


      Add a message about pin usage in Banking#openBank (Thanks @Todd)


      Disable the firewall by default (Thanks @Todd)


      Fix handling of the welcome screen after login (Thanks @Encoded)


      Fix wrong amount bank withdrawal (Thanks @Encoded)


      Fix Screen#isInViewport


      Fix Game#isInViewport (Thanks @Encoded)


      Call onBreakEnd for ListenerManager Breaking Listeners (Thanks @Encoded)


      Fix Prayer#getPrayerPoints NumberFormatException (Thanks @JoeDezzy1)



      Note: If you are using LG, please restart both the RS client and TRiBot.
        • Thanks
        • Like
      • 28 replies
    • 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
        • Like
      • 64 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
        • Like
      • 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
        • Like
      • 34 replies
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...