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
  • isInCombat returning incorrectly?


    Rubick
     Share

    Recommended Posts

    I have a checker before attacking an NPC:

    if (!chicken.isInCombat()) {
                        chicken.interact("Attack")) 
                        }
                    
    

    Why is it still attacking chickens already in combat with other players?

    Link to comment
    Share on other sites

    I have a checker before attacking an NPC:

    if (!chicken.isInCombat()) {
                        chicken.interact("Attack")) 
                        }
                    
    

    Why is it still attacking chickens already in combat with other players?

     

    Likely because when you declared the chicken object it wasn't in combat, though it could be broken. Is your chicken being updated (looped over)? Using a filter instead might be easier.

     

    Edit: If it is broken try adding Noodle's suggestion to the filter.

    //I didn't type this in an IDE so you might need to fix a syntax error or two =)
    NPC chicken = getNpcs().closest(c -> c != null && c.getName().equals("Chicken") && !c.isInCombat);
    if (chicken != null && !getLocalPlayer.isInCombat())
      chicken.interact("Attack");
    
    Edited by Genius
    Link to comment
    Share on other sites

     

    You should be able to do this for now.

    if (!chicken.isInCombat() && !chicken.isInteractedWith()) {

     

    Is IsInCombat() working as intended or is that part of the API bugged? Thanks for the work around.

    Link to comment
    Share on other sites

    Is IsInCombat() working as intended or is that part of the API bugged? Thanks for the work around.

     

    Run a script with this in your onLoop to test then just fight some stuff:

    @Override
        public int onLoop() {
            log("In combat: " + String.valueOf(getLocalPlayer().isInCombat()));
            return 1000;
        }
    
    Link to comment
    Share on other sites

     

    Run a script with this in your onLoop to test then just fight some stuff:

    @Override
        public int onLoop() {
            log("In combat: " + String.valueOf(getLocalPlayer().isInCombat()));
            return 1000;
        }
    

     

    Ah, good thinking. I'll test this out tomorrow. Got the script running with 's fix to see if that works out of curiosity first.

    Edited by Rubick
    Link to comment
    Share on other sites

    Checking it out

    Seems to be working for me, if you find any scenarios where it's wrong let me know :)

     

    I have a filter such as this:

    final Player p = getPlayers().closest(player -> player != null && player.exists() && player.isInCombat() && player.getInteractingCharacter() != null && player.isInteracting(getLocalPlayer()));

    It returns true even though the player trades me instead of attacking in the wilderness.

    Link to comment
    Share on other sites

    I have a filter such as this:

    final Player p = getPlayers().closest(player -> player != null && player.exists() && player.isInCombat() && player.getInteractingCharacter() != null && player.isInteracting(getLocalPlayer()));

    It returns true even though the player trades me instead of attacking in the wilderness.

     

     

    There's no way we can differentiate between attacking / trading, they both just show as interacting with (our basis for isInCombat).

    Link to comment
    Share on other sites

    There's no way we can differentiate between attacking / trading, they both just show as interacting with (our basis for isInCombat).

     

    #isInCombat checks for interaction? I guess I should add a check for health bar visibility.

    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.