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
  • Overriding if statement


    tmp
     Share

    Recommended Posts

    I have this script with two if statements and I need one to override the other asap when it happens
     

    The problem im having is that when eatFood() function is happening, it cant execute anything inside the other if -statement.
    e.g. if the bot is currently eating food, I need it to stop eating and skip to getting the animation of the NPC
    When the eatFood() is over, the animation has already ended, and it skips the getAnimation

    if (xNPC != null) {
      if (context.getCombat().getHealthPercent() <= 70) {
       eatFood();
      } 
      else if (xNPC.getAnimation == 1000) {
        //Do something important stuff
      }
    }
    
    private void eatFood() {
      Item food = context.getInventory().get(item -> item != null && item.getName().contains("Shark"));
      if (food != null) {
        food.interact("Eat");
        sleepUntil(() -> context.getCombat().getHealthPercent() > 70, 1500);
       } 
    }

    I'd appreciate if you guys would guide me towards right path

    Link to comment
    Share on other sites

    The way your logic is structured is flawed for what you want. The if statement in regards to the npc anim won't fire if the health is below your value, and that may take a tick to register it isn't after the eat food method is triggered due to your else statement. 

    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.