Jump to content

Checking for item in equipment slot


Aviri

Recommended Posts

I'm trying to see if my player has a ring of dueling in his equipment slot, but I am getting a NullPointerException.

Here is what I have so far, and it is not working.

if(!equipment.getItemInSlot(9).getName().startsWith("Ring of dueling")) {
				bank.withdraw(2552, 1); //withdraws ring of dueling(8)
			} else
					log("Already have a Ring of dueling.");

Does this work (if done correctly) if my bot currently has the bank open? Or do I have to tell it to open the eqiupment tab first, and then check if it has a ring or not?

 

Also, another thing I am having trouble with is using an inventory item on an object. Ex: Using a key on a door. How would I go about doing that?

 

Thanks for any help, in advance.

Edited by Aviri
Link to comment
Share on other sites

I'm trying to see if my player has a ring of dueling in his equipment slot, but I am getting a NullPointerException.

Here is what I have so far, and it is not working.

Thanks for any help, in advance.

if(!equipment.getItemInSlot(9).getName().startsWith("Ring of dueling")) {
				bank.withdraw(2552, 1); //withdraws ring of dueling(8)
			} else
					log("Already have a Ring of dueling.");

Also, last thing, does this work (if done correctly) if my bot currently has the bank open? Or do I have to tell it to open the eqiupment tab first, and then check if it has a ring or not?

you are getting a npe when your checking the name of the item in slot 9. But you never did a null check on your item.

equipment.getItemInSlot(9) != null
//check name

when you first start a fresh client the bot has to check your equipment tab once. Ince that is done it can remember what tems you have on and dont need to close the bank.

Edited by Joseph
Link to comment
Share on other sites

Try,

if(equipment.isWearingItem(EquipmentSlot.RING, "dueling"))
{

}

Because if they don't have anything equipped then Item would be null and then you'd be trying to call the .getName() method on a null object, hints the null pointer.

 

Nope, getting a NullPointerException again. Note, this is with a ring of dueling equipted and without it equipted.

[ERROR][Bot #1][10/03 05:05:07 PM]: Error in script executor!
java.lang.NullPointerException
	at org.osbot.rs07.api.Equipment.getItems(yi:195)
	at org.osbot.rs07.api.util.ItemContainer.filter(ji:112)
	at org.osbot.rs07.api.Equipment.isWearingItem(yi:137)
	at org.osbot.rs07.api.Equipment.isWearingItem(yi:130)
	at main.onLoop(main.java:82)
	at org.osbot.rs07.event.ScriptExecutor$InternalExecutor.run(ck:136)
	at java.lang.Thread.run(Unknown Source)

Also, I edited the bottom of my original post with another question, let me know if you can help.

Thank you! :)

you are getting a npe when your checking the name of the item in slot 9. But you never did a null check on your item.

equipment.getItemInSlot(9) != null
//check name

when you first start a fresh client the bot has to check your equipment tab once. Ince that is done it can remember what tems you have on and dont need to close the bank.

 

Does the bot do this check automatically, or do I have to do that check within my script?

Thank you for your help!

Link to comment
Share on other sites

Also, another thing I am having trouble with is using an inventory item on an object. Ex: Using a key on a door. How would I go about doing that?

 

Thanks for any help, in advance.

if (!getInventory().isItemSelected()) {
	getInventory().getItem("steel bar").interact("Use");
	sleep(gRandom(400, 100));
} else {	
	if (getInventory().getSelectedItemName().equalsIgnoreCase("steel bar")) {
		getObjects().closest(FURN).interact("Smelt", "Use");
		sleep(gRandom(700, 100));
	}
|

Does the bot do this check automatically, or do I have to do that check within my script?

Thank you for your help!

on its own, but if you can do it too by easily opening setting tab

Edited by Joseph
  • Like 1
Link to comment
Share on other sites

what does that method do? to lazy to check lol. 

equips it  idk it works for me

 

 

This is how i use it

if (!getTabs().getOpen().equals(Tab.INVENTORY)) getTabs().open(Tab.INVENTORY);
        getEquipment().equip(EquipmentSlot.RING,"Ring of dueling(8)");
Edited by TheObserver
Link to comment
Share on other sites

Alright, last error I am getting:

The method closest(Filter<RS2Object>...) in the type EntityAPI<RS2Object> is not applicable for the arguments (RS2Object)
RS2Object DOOR = objects.closest("Door");

getObjects().closest(DOOR).interact("Open", "Use");

I assume I am initializing DOOR incorrect to work with the closest method, but not too sure how to go about fixing it.

Link to comment
Share on other sites

Alright, last error I am getting:

The method closest(Filter<RS2Object>...) in the type EntityAPI<RS2Object> is not applicable for the arguments (RS2Object)
RS2Object DOOR = objects.closest("Door");

getObjects().closest(DOOR).interact("Open", "Use");

I assume I am initializing DOOR incorrect to work with the closest method, but not too sure how to go about fixing it.

objects.closest is the same thing as getObjects().closest so basically what you're doing now is getObjects().closest(objects.closest("Door"))

Also, the return value of objects.closest can be null so you should check for that before calling interact :)

  • Like 1
Link to comment
Share on other sites

objects.closest is the same thing as getObjects().closest so basically what you're doing now is getObjects().closest(objects.closest("Door"))

Also, the return value of objects.closest can be null so you should check for that before calling interact smile.png

Welp, didn't even realize that. Thanks for getting me there, and the helpful tip :D

Link to comment
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.

  • Recently Browsing   0 members

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