Jump to content

Help Improve my Fighting Sleep/Looting Method


Magarac

Recommended Posts

new ConditionalSleep(30000) {
                        @Override
                        public boolean condition() throws InterruptedException {
                            return (!combat.isFighting() || enemy.getHealthPercent() == 0) || lowHealth() || (loot != null && loot.isOnScreen());
                        }
                    }.sleep();

 

So I want it to chill while fighting unless it's either done fighting, the enemy is dead, we are at low HP (to heal), or there is loot nearby.

 

Currently how it loots is:

Kills an enemy, runs onto the next one (while loot from first enemy slowly appears), then once second enemy is dead it loots the first drop and goes onto the third enemy.

TL;DR it doesn't wait for the drop, so by the end of the inventory it fights another enemy before fully filling the inventory. :doge:

Link to comment
Share on other sites

1 minute ago, Juggles said:

This will prioritize eating >loot> attacking

My script is in states so I have Healing as one of the top priorities, not too worried about it. I also have Looting as the first thing it does, but I just want it to Loot while in the middle of a fight, and am curious why the code I have isn't returning the fight sleep. :cate:

Link to comment
Share on other sites

1 minute ago, Magarac said:

My script is in states so I have Healing as one of the top priorities, not too worried about it. I also have Looting as the first thing it does, but I just want it to Loot while in the middle of a fight, and am curious why the code I have isn't returning the fight sleep. :cate:

My code will loot in the middle of the fight.

Link to comment
Share on other sites

Just now, Juggles said:

My code will loot in the middle of the fight.

Are you using a conditional sleep? I'm just curious how you get out of it to be able to loot, since mine isn't doing it efficiently.

 

case FIGHT:
                // enemy declaration
                NPC enemy = getNpcs().closest(new Filter<NPC>() {
                    @Override
                    public boolean match(NPC npc) {
                        return npc.getName().contains("enemy") && (npc != null) && !npc.isUnderAttack() && (npc.getHealthPercent() > 0) && map.canReach(npc);
                    }
                });
                // loots
                GroundItem loot = getGroundItems().closest("");
                if (loot != null && loot.isVisible()) {
                    if (getInventory().isFull() && gotFood()) {
                        getInventory().interact("Eat", food);
                        Loot();
                    } else {
                        Loot();
                    }
                }
                // fights
                if ((!myPlayer().isUnderAttack() && myPlayer().getInteracting() == null && !combat.isFighting()) || !enemy.isInteracting(myPlayer())) {
                    if (enemy != null && enemy.isAttackable()) {
                        enemy.interact("Attack");
                        state = "Fighting a enemy.";
                        new ConditionalSleep(5000) {
                            @Override
                            public boolean condition() throws InterruptedException {
                                return (enemy.isUnderAttack());
                            }
                        }.sleep();
                        new ConditionalSleep(30000) {
                            @Override
                            public boolean condition() throws InterruptedException {
                                return (!combat.isFighting() || enemy.getHealthPercent() == 0) || lowHealth() || (loot != null && loot.isOnScreen());
                            }
                        }.sleep();
                    }
                }
                else if (myPlayer().isUnderAttack() && !combat.isFighting() && enemy.isInteracting(myPlayer())){
                    if (enemy != null && enemy.isAttackable()) {
                        enemy.interact("Attack");
                        state = "Fighting a enemy.";
                        new ConditionalSleep(5000) {
                            @Override
                            public boolean condition() throws InterruptedException {
                                return (enemy.isUnderAttack());
                            }
                        }.sleep();
                        new ConditionalSleep(30000) {
                            @Override
                            public boolean condition() throws InterruptedException {
                                return (!combat.isFighting() || enemy.getHealthPercent() == 0) || lowHealth() || (loot != null && loot.isOnScreen());
                            }
                        }.sleep();
                    }
                }
                else if (myPlayer().isUnderAttack() && combat.isFighting() && enemy.isInteracting(myPlayer())){
                    state = "Fighting a enemy.";
                    new ConditionalSleep(30000) {
                        @Override
                        public boolean condition() throws InterruptedException {
                            return (!combat.isFighting() || enemy.getHealthPercent() == 0) || lowHealth() || (loot != null && loot.isOnScreen());
                        }
                    }.sleep();
                }
                break;

The 3 different fighting if statements are:

1) if my player is not interacting in any way, it initiates a fight OR if an enemy other than the one I want is fighting me, it initiates a fight

2) if my player is being attacked but is not retaliating, it attacks OR if an enemy other than the one I want is fighting me, it initiates a fight

3) if my player is being attacked by my enemy and is retaliating, it waits.

 

I have it return if loot is nearby and it loots as seen above. Healing works just fine the way I have it. Any thoughts?

Link to comment
Share on other sites

16 minutes ago, Juggles said:

if (HP<int) {

//eat 

} else if (loot.exists) {

//loot item

} else {

if (combat.isFighting) {

//chill

} else {

// attack NPC

}

}

This will prioritize eating >loot> attacking

After attack NPC, you can sleep until my player is fighting. Like 3-5 seconds is fine. 

sleep until my player is fighting.

 

Then it will prioritize looting and wont spam click. 

Link to comment
Share on other sites

2 minutes ago, Juggles said:

After attack NPC, you can sleep until my player is fighting. Like 3-5 seconds is fine. 

sleep until my player is fighting.

 

Then it will prioritize looting and wont spam click. 

Wait up so you mean to remove the whole sleep while fighting? So something like this?

enemy.interact("Attack");
state = "Fighting a enemy.";
new ConditionalSleep(5000) {
  @Override
    public boolean condition() throws InterruptedException {
    return (myPlayer().isFighting());
  }
}.sleep();

Am I not understanding what the isFighting function entails?

Link to comment
Share on other sites

1 minute ago, Magarac said:

Wait up so you mean to remove the whole sleep while fighting? So something like this?


enemy.interact("Attack");
state = "Fighting a enemy.";
new ConditionalSleep(5000) {
  @Override
    public boolean condition() throws InterruptedException {
    return (myPlayer().isFighting());
  }
}.sleep();

Am I not understanding what the isFighting function entails?

Yes this is good. So it will sleep until you are fighting. 

Now you have a combat.isFighting state where it does nothing. 

If you have eating and looting prioritized, it will automatically go to those states 

Link to comment
Share on other sites

1 minute ago, Juggles said:

Yes this is good. So it will sleep until you are fighting. 

Now you have a combat.isFighting state where it does nothing. 

If you have eating and looting prioritized, it will automatically go to those states 

Ohh okay makes a lot of sense now. Do you think my 3 different fight conditions are necessary up there? Especially if in an area with more than one NPC that is aggressive? What's the best way to solve that.

If you don't mind, can you take a look at the below code and tell me if it's along the lines of what you said?

 

if (!combat.isFighting()) {
  enemy.interact("Attack");
  state = "Fighting a enemy.";
  new ConditionalSleep(5000) {
    @Override
      public boolean condition() throws InterruptedException {
      return (myPlayer().isFighting());
    }
  }.sleep();
}
else {
	new ConditionalSleep(50000) {
    @Override
      public boolean condition() throws InterruptedException {
      return (!combat.isFighting() || lowHealth() || loot != null && loot.isVisible());
    }
  }.sleep();

 

Link to comment
Share on other sites

Well instead of having this, you don't need anything in this case at all. 

new ConditionalSleep(50000) {
    @Override
      public boolean condition() throws InterruptedException {
      return (!combat.isFighting() || lowHealth() || loot != null && loot.isVisible());
    }
  }.sleep();

 

 

I would do it like this

if (HP<int) {

//eat

} else if (loot.exists) {

//loot 

} else {

if (!combat.isFighting()) {
  enemy.interact("Attack");
  state = "Fighting a enemy.";
  new ConditionalSleep(5000) {
    @Override
      public boolean condition() throws InterruptedException {
      return (myPlayer().isFighting());
    }
  }.sleep();
}
else {
	
}

}

 

Or you could do it like this. It will return state nothing when you are fighting since it is the last one that is true. 


 

if (HP<int) {

return state.EAT;

}



if (loot.exists) {

return state.LOOT;

}



if (!combat.isFighting) {

return state.ATTACK;

}



return state.NOTHING;

















now in your loop you have 

case ATTACK;

//Attack NPC

//sleep until in 

 enemy.interact("Attack");
  state = "Fighting a enemy.";
  new ConditionalSleep(5000) {
    @Override
      public boolean condition() throws InterruptedException {
      return (myPlayer().isFighting());
    }
  }.sleep();



break;

 

Link to comment
Share on other sites

14 minutes ago, Juggles said:

I would do it like this

Amazing! I changed it around and now it's way cleaner and works perfect. Thanks a ton man!

Now my only problem is a fighting one :P

In a multi-combat area with aggressive NPCs, how do I differentiate who it's fighting with and run away from the non-intended NPCs. But overall a huge improvement! Ty!

Link to comment
Share on other sites

12 minutes ago, Magarac said:

Amazing! I changed it around and now it's way cleaner and works perfect. Thanks a ton man!

Now my only problem is a fighting one :P

In a multi-combat area with aggressive NPCs, how do I differentiate who it's fighting with and run away from the non-intended NPCs. But overall a huge improvement! Ty!

You can filter through the NPCs by doing something like this:

 

NPC npcname = npcs.closest(n -> n.getName().equals("npcname") && fightingArea.contains(n) && !n.isHitBarVisible() && n.getHealthPercent() > 0 && n.getInteracting() == null)

I'm pretty sure that would give the NPC which isnt currently under attack or interacting with anyone so you can do what you wish with them after.

  • Like 1
Link to comment
Share on other sites

10 minutes ago, zenitftw said:

You can filter through the NPCs by doing something like this:

 

NPC npcname = npcs.closest(n -> n.getName().equals("npcname") && fightingArea.contains(n) && !n.isHitBarVisible() && n.getHealthPercent() > 0 && n.getInteracting() == null)

I'm pretty sure that would give the NPC which isnt currently under attack or interacting with anyone so you can do what you wish with them after.

Thanks man, but I already have an NPC filter! Appreciate it anyways. I meant more along the lines of when checking combat.isFighting to know who it is actually fighting with, cause it'll return true in any combat if I am not mistaken, not just with my specified NPC. Therefore if I run into an aggro/multi-combat area and a different NPC fights me, it'll return true and finish the fight before attacking who I intend. Right?

Link to comment
Share on other sites

10 minutes ago, Magarac said:

Thanks man, but I already have an NPC filter! Appreciate it anyways. I meant more along the lines of when checking combat.isFighting to know who it is actually fighting with, cause it'll return true in any combat if I am not mistaken, not just with my specified NPC. Therefore if I run into an aggro/multi-combat area and a different NPC fights me, it'll return true and finish the fight before attacking who I intend. Right?

Im not sure I understand, but If you are asking how to check which monster you are fighting with after running into an aggro/multi combat zone you can use something like myPlayer().getInteracting() and it will return the name of the monster which you are fighting.

 

so you can do something like

 if(myPlayer().getInteracting() == "undesired npc name")

   run away;

else

continue fight

 

Edited by zenitftw
Link to comment
Share on other sites

12 minutes ago, zenitftw said:

Im not sure I understand, but If you are asking how to check which monster you are fighting with after running into an aggro/multi combat zone you can use something like myPlayer().getInteracting() and it will return the name of the monster which you are fighting.

 

so you can do something like

 if(myPlayer().getInteracting() == "undesired npc name")

   run away;

else

continue fight

 

Ohhh damn that makes so much sense, duh. Thanks man appreciate it! I get it now.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...