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


    tmp

    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

    Archived

    This topic is now archived and is closed to further replies.

    ×
    ×
    • 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.