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

    • [CONTEST ANNOUNCEMENT] 2019 Botter's Choice Awards
      2019 Botter’s Choice Awards

      To celebrate the launch of our TRiBot Official RuneScape Bot Blog,

      we’re doing a giveaway! 

      The TRiBot Official RuneScape Bot Blog: 

      Teaching you how to do more advanced botting, faster.
      Contest Details

      Prize: 3 winners will be selected to win 25 TRiBot credits.

      How to enter:

      Respond to this forum post by November 12th tagging the thread for: 

      Your favorite script

      Provide a brief explanation (1-2 sentences) why you think that script should be put in the top 5. 

      Who can enter?

      Botter’s who are not currently scripters. Sorry scripters, the people are going to vote. Your contest is here.

      The top 5 in each category will be showcased on our TRiBot Official RuneScape Bot Blog in a “People’s Choice” section and promoted across the TRiBot website. 

      -- Credits will be awarded based on thoughtfulness and humor -- 

      Bonus points

      Use a meme in your explanation. Because we all love memes.

      *no purchase necessary. Winners will be announced on Friday, November 15, 2019 at 4:00 p.m. on our News and Announcements forum. 

      -- Vote Below -- 
        • Like
      • 28 replies
    • [READ TO THE END FOR A TEASER]

      I've noticed some new TRiBotters have had some troubles finding out sources of how to do certain things, such as using advanced scripts and often get lost in the forums.

      We are still getting posts asking where to start, what to do, recommended scripts, etc. 

      As many of you know, I am new to the team, and had troubles myself learning how to bot, let alone script. 

      So, what our team decided to do was make it easier to learn how to bot, how to script, and just become an overall better botter and scripter faster. 

      As some of you might have seen, I've posted 3 new blogs, you can check it out by clicking on the following picture or here.


      These first 3 blogs are the first of many blogs that will be TRiBot official. They are encouraged to be challenged, improved upon and act as A Best Practices Guide for Botters.

      What information would you like to see in the blogs?

      👇 [TEASER] 👇

      .

      .

      .

      We are going to be hosting a  CONTEST  this  OCTOBER.

      Its scary to think how soon you'll find out.👻

      Stay tuned.


      - RileyZ
      • 8 replies
    • Today marks a big day for TRiBot! To make it easier for users to use TRiBot, we've created installers available for every platform! These installers are all bundled with the latest version of OpenJDK 1.8 (Java 😎, which is LG compatible.

      Using TRiBot is now easy. Simply download the installer for your platform, install TRiBot, and run it. The TRiBot Loader will correctly identify the bundled JDK so there's no need to change the Java selection.

      Windows

      EXE installer: TRiBot-windows-x64-4.0.3.exe


      MSI installer: TRiBot-windows-x64-4.0.3.msi


      Portable version: TRiBot-windows-x64-4.0.3.zip


      Mac OS

      Installer: TRiBot-macos-4.0.3.dmg


      Portable version: TRiBot-macos-4.0.3.tgz


      Unix/Linux

      Installer: TRiBot-unix-4.0.3.sh


      RPM installer (CentOS/Fedora): TRiBot-linux-4.0.3.rpm


      DEB installer (Debian): TRiBot-linux-4.0.3.deb


      Portable version: TRiBot-unix-4.0.3.tar.gz


      Platform Independent

      JAR file: tribot-loader-4.0.3.jar


      Note that this jar file does not include the bundled JDK.



      Windows and Mac OS users may notice a warning message stating that the installer/application is un-recognized or un-trusted. Please ignore this message and proceed with running the installer/application. We need to acquire a code signing certificate so that we can sign the installers letting the operating system know that these files can be trusted. It will take a week or more to acquire one, so please hold tight.

      Other notable changes to the TRiBot Loader:

      Support getting the version from OpenJDK distributions


      Add check for bundled JDK


      Copy OpenJDK tools.jar to the bundled JDK if not present


      Set the current java as the first available list entry


      Ignore Java versions which are symbolic links


      Make the bundled JDK the preferred Java version


      Update icon images


      Reduce the number of HTTP calls
        • Thanks
        • Like
      • 19 replies
    • TRiBot is looking to improve a lot of its customer relationship management, customer on boarding process, customer experience, design elements, community engagement and pretty much everything else you can imagine when it comes to marketing.

      Our goal: To ensure that the marketing done TRULY reflects the experience and does not shine an inaccurate light on what TRiBot is lacking in.

      So I ask, what do you love about TRiBot and what do you hate about TRiBot? What does O S Bot, Rune M8, PowR Bot and Dre amBot do better? (yes I purposely didn't spell it right 😂).

      Love, 

      RileyZ
        • Like
      • 18 replies
    • Hello TRiBot,

      Today we have a significant release that has been in the works for the last month addressing several key issues, features and bugs in the backlog.

      With these changes, we are also including a new TRiBot Loader which will allow you to select any version that is released. This adds the flexibility of allowing you to revert to a previous version should an issue arise, run development only builds, view an accurate change log between versions etc. we are very proud to offer this feature and think it will add a lot more functionality down the road as we continue to release new versions.

      These changes include 80+ commits by our development team, a list of them is summarized below and also available for your viewing pleasure in the new TRiBot Loader.

      In addition, we have taken additional steps to improve as a development team by adding continuous integration and deployment into our workflow to assist in delivering timely releases such as bug fixes as well as new features on a weekly basis depending on our development cycle.
        • Thanks
        • Like
      • 39 replies
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...