Jump to content
Frequently Asked Questions
  • Are you not able to open the client? Try following our getting started guide
  • Still not working? Try downloading and running JarFix
  • Help! My bot doesn't do anything! Enable fresh start in client settings and restart the client
  • How to purchase with PayPal/OSRS/Crypto gold? You can purchase vouchers from other users
  • Try asking for help in the chatbox
  • Looting issue?


    beefsteak
     Share

    Recommended Posts

    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;

    Link to comment
    Share on other sites

    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

    Link to comment
    Share on other sites

    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;

     

     
    Link to comment
    Share on other sites

    Create an account or sign in to comment

    You need to be a member in order to leave a comment

    Create an account

    Sign up for a new account in our community. It's easy!

    Register a new account

    Sign in

    Already have an account? Sign in here.

    Sign In Now
     Share

    ×
    ×
    • Create New...

    Important Information

    We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.