Aviri Posted October 3, 2015 Share Posted October 3, 2015 (edited) 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 October 4, 2015 by Aviri Quote Link to comment Share on other sites More sharing options...
Zero Posted October 4, 2015 Share Posted October 4, 2015 (edited) 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. Edited October 4, 2015 by Zero Quote Link to comment Share on other sites More sharing options...
Joseph Posted October 4, 2015 Share Posted October 4, 2015 (edited) 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 October 4, 2015 by Joseph Quote Link to comment Share on other sites More sharing options...
Aviri Posted October 4, 2015 Author Share Posted October 4, 2015 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! Quote Link to comment Share on other sites More sharing options...
Joseph Posted October 4, 2015 Share Posted October 4, 2015 (edited) 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 October 4, 2015 by Joseph 1 Quote Link to comment Share on other sites More sharing options...
Aviri Posted October 4, 2015 Author Share Posted October 4, 2015 Thanks a lot Joseph! You da best. I'll update this post if I've fixed it, still a good 'ol begginner so it's been rough. Quote Link to comment Share on other sites More sharing options...
Chris Posted October 4, 2015 Share Posted October 4, 2015 !getEquipment().isWearingItem(EquipmentSlot.RING) Quote Link to comment Share on other sites More sharing options...
Aviri Posted October 4, 2015 Author Share Posted October 4, 2015 !getEquipment().isWearingItem(EquipmentSlot.RING) Your comment came in a the perfect time. ily Quote Link to comment Share on other sites More sharing options...
Chris Posted October 4, 2015 Share Posted October 4, 2015 Your comment came in a the perfect time. ily getEquipment().equip(EquipmentSlot.RING,"Ring of dueling(8)"); Quote Link to comment Share on other sites More sharing options...
Joseph Posted October 4, 2015 Share Posted October 4, 2015 getEquipment().equip(EquipmentSlot.RING,"Ring of dueling(8)"); what does that method do? to lazy to check lol. Quote Link to comment Share on other sites More sharing options...
Chris Posted October 4, 2015 Share Posted October 4, 2015 (edited) 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 October 4, 2015 by TheObserver Quote Link to comment Share on other sites More sharing options...
Aviri Posted October 4, 2015 Author Share Posted October 4, 2015 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. Quote Link to comment Share on other sites More sharing options...
Flamezzz Posted October 4, 2015 Share Posted October 4, 2015 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 1 Quote Link to comment Share on other sites More sharing options...
Aviri Posted October 4, 2015 Author Share Posted October 4, 2015 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 Welp, didn't even realize that. Thanks for getting me there, and the helpful tip Quote Link to comment Share on other sites More sharing options...