beefsteak 30 Posted July 7, 2020 Hey, having some issues with my fighting case, I'm getting an error with the looting bones line. Total beginner scripter, so I'm sure theres a better way to write this. Thanks case FIGHTING: log("Fighting"); NPC currentNpc = getNpcs().closest( npc -> npc != null && npc.getName() != null && npc.getName().equals("Cow") && !npc.isInCombat() && npc.getInteractingCharacter() == null); GroundItem bones = getGroundItems().closest("Bones"); if (currentNpc != null) { if (!getLocalPlayer().isInCombat() && getLocalPlayer().getInteractingCharacter() == null) { if (currentNpc.interact("Attack")) { sleepUntil( () -> getLocalPlayer().isInCombat() || getLocalPlayer() .getInteractingCharacter() != null, 3000); if (bones.isOnScreen() && bones != null) { bones.interact("Take"); } } } } break;
MaxTuna 5 Posted July 7, 2020 You should null check before you call bones.isOnScreen() or you will get null pointer error every time there are no bones on the ground
Stoned 52 Posted July 7, 2020 Would have been helpful to provide the error log however the below should work: case FIGHTING: log("Fighting"); NPC currentNpc = getNpcs().closest( npc -> npc != null && npc.getName() != null && npc.getName().equals("Cow") && !npc.isInCombat() && npc.getInteractingCharacter() == null); GroundItem bones = getGroundItems().closest("Bones"); if(bones != null && bones.isOnScreen()){ bones.interact("Take"); sleep(300); } if (currentNpc != null) { if (!getLocalPlayer().isInCombat() && getLocalPlayer().getInteractingCharacter() == null) { if (currentNpc.interact("Attack")) { sleepUntil( () -> getLocalPlayer().isInCombat() || getLocalPlayer() .getInteractingCharacter() != null, 3000); } } } break;
Recommended Posts
Archived
This topic is now archived and is closed to further replies.