Et43 2 Share Posted November 11, 2020 So im in the process of making a Jug filler and currently what i need it to do is to use a jug on the fountain ive tried the following npc = getNpcs().closest(fountain -> fountain != null && fountain.getName().contentEquals("Small fountain")); getInventory().interact(jugId, "Use"); npc.interact(); Error Code: 6:20:26 PM: [ERROR] Exception has occurred while running! Please report error to developer if problem persists: java.lang.NullPointerException at filler.onLoop(filler.java:62) at org.dreambot.api.script.AbstractScript.run(AbstractScript.java) at java.lang.Thread.run(Unknown Source) And ive done the same with GameObject, but still get the same error. Any idea on how to fix? Link to comment Share on other sites More sharing options...
7804364 230 Share Posted November 11, 2020 Fountain is a gameobject not an npc so do getGameObjects().closest(fountain -> fountain != null && fountain.getName().contentEquals("Small fountain")); Link to comment Share on other sites More sharing options...
Hashtag 8692 Share Posted November 11, 2020 Fountain isn't a NPC, it's a GameObject. Also, you should have null checks to avoid getting NullPointerExceptions. The Item class has the method useOn(Entity e), which you should use instead of what you're currently doing to use the item on a fountain. Link to comment Share on other sites More sharing options...
Et43 2 Author Share Posted November 11, 2020 2 hours ago, Hashtag said: Fountain isn't a NPC, it's a GameObject. Also, you should have null checks to avoid getting NullPointerExceptions. The Item class has the method useOn(Entity e), which you should use instead of what you're currently doing to use the item on a fountain. How would you declare what the item is using the Item class.( sorry for the question, new to java but got 2years of python to help me understand just a little ) Link to comment Share on other sites More sharing options...
Hashtag 8692 Share Posted November 11, 2020 I'm not sure what you're asking me, but here's what you're after Item jugOfWater = Inventory.get("Jug of water"); if (jugOfWater != null) { // do we have it in our inv? GameObject fountain = GameObjects.closest("Fountain"); if (fountain != null) { // does the fountain exist? if (jugOfWater.useOn(fountain)) { // interaction successful } } } Link to comment Share on other sites More sharing options...
Et43 2 Author Share Posted November 12, 2020 14 hours ago, Hashtag said: I'm not sure what you're asking me, but here's what you're after Item jugOfWater = Inventory.get("Jug of water"); if (jugOfWater != null) { // do we have it in our inv? GameObject fountain = GameObjects.closest("Fountain"); if (fountain != null) { // does the fountain exist? if (jugOfWater.useOn(fountain)) { // interaction successful } } } Ye thats what i was asking, thx m8. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.