Jump to content

"NPC Could not be resolved"


Recommended Posts

Posted

NPCs closest returns a single NPC, not a collection of NPCs for you to filter.

 

You want something like:

 Optional<NPC> suitableNpc = getNpcs().getAll().stream().filter(npc -> npc.getHealthPercent() > 1).findFirst();
        if (suitableNpc.isPresent()) {
            suitableNpc.get().interact("examine");
        }

You may want to look a little bit into Java 8 streams before using them.

 

 

Edit:

Or better yet you can use the FilterAPI way which is native to OSBot smile.png
 

getNpcs().closest(new Filter<NPC>() {
            @[member='Override']
            public boolean match(NPC obj) {
                return obj.getHealthPercent() > 1;
            }
        }) ;

 

EntityAPI: http://osbot.org/api/org/osbot/rs07/api/EntityAPI.html

  • Like 1
Posted

Thanks alot guys~ 

 

     if(cowArea.contains(myPlayer())) {      
    NPC cow = getNpcs().closest("Cow", "Cow calf");
    if (cow != null && !combat.isFighting() && !cow.isUnderAttack()) {
    cow.interact("Attack");
    new ConditionalSleep(5000) {
    @@Override
    public boolean condition() throws InterruptedException {
    return myPlayer().isAnimating() || myPlayer().isInteracting(cow);
    }
    }.sleep();  
    }
 
is what i used.
 
I have one last problem. For some reason it takes a LONG time to loot cowhide/choose a different NPC (after killing cow, finding out someone already attking it or if it's under attk.)
 
thanks
Posted

 

Thanks alot guys~ 

 

     if(cowArea.contains(myPlayer())) {      
    NPC cow = getNpcs().closest("Cow", "Cow calf");
    if (cow != null && !combat.isFighting() && !cow.isUnderAttack()) {
    cow.interact("Attack");
    new ConditionalSleep(5000) {
    @@Override
    public boolean condition() throws InterruptedException {
    return myPlayer().isAnimating() || myPlayer().isInteracting(cow);
    }
    }.sleep();  
    }
 
is what i used.
 
I have one last problem. For some reason it takes a LONG time to loot cowhide/choose a different NPC (after killing cow, finding out someone already attking it or if it's under attk.)
 
thanks

 

 

 

Think about it logically, you're using "closest". It will always return the closest cow to you and if that closest cow is under attack then you are going to be waiting until that cow is killed.

Use one of the methods above to filter cows by distance/area, health > 0, not under attack, etc. After that you're going to want to sort those results by distance. This way you only get cows which you can attack, ordered by distance (instead of all cows which you don't know if you can attack or not).

Posted

Think about it logically, you're using "closest". It will always return the closest cow to you and if that closest cow is under attack then you are going to be waiting until that cow is killed.

Use one of the methods above to filter cows by distance/area, health > 0, not under attack, etc. After that you're going to want to sort those results by distance. This way you only get cows which you can attack, ordered by distance (instead of all cows which you don't know if you can attack or not).

if (cowArea.contains(myPlayer())) {
NPC cow = getNpcs().closest("Cow", "Cow calf");
if (cow != null && !combat.isFighting() && !cow.isUnderAttack()) {
cow.interact("Attack");
new ConditionalSleep(5000) {
public boolean condition() throws InterruptedException {
return myPlayer().isAnimating()
|| myPlayer().isInteracting(cow);
}
}.sleep();
}
if (cow.getHealthPercent() == 0) {
sleep(1000);
GroundItem cowhide = groundItems.closest("Cowhide");
if (cowhide != null && cowhide.interact("Take")) {
new ConditionalSleep(5000) {
public boolean condition()
throws InterruptedException {
return cowhide == null;
}
}.sleep();
}
}
} else {
getWalking().webWalk(cowArea);
}
 
I have it like this. I'm tlaking about after the cow is dead too. For some reason it takes too long to find another cow/simply loot cowhide. Is there a way to prioritize looting cowhide over killing? so i can find cowhide on the ground and pick itup. thanks
Posted

 

if (cowArea.contains(myPlayer())) {
NPC cow = getNpcs().closest("Cow", "Cow calf");
if (cow != null && !combat.isFighting() && !cow.isUnderAttack()) {
cow.interact("Attack");
new ConditionalSleep(5000) {
public boolean condition() throws InterruptedException {
return myPlayer().isAnimating()
|| myPlayer().isInteracting(cow);
}
}.sleep();
}
if (cow.getHealthPercent() == 0) {
sleep(1000);
GroundItem cowhide = groundItems.closest("Cowhide");
if (cowhide != null && cowhide.interact("Take")) {
new ConditionalSleep(5000) {
public boolean condition()
throws InterruptedException {
return cowhide == null;
}
}.sleep();
}
}
} else {
getWalking().webWalk(cowArea);
}
 
I have it like this. I'm tlaking about after the cow is dead too. For some reason it takes too long to find another cow/simply loot cowhide. Is there a way to prioritize looting cowhide over killing? so i can find cowhide on the ground and pick itup. thanks

 

 

 

For the love of god please use the code formatting 

Posted (edited)

NPCs closest returns a single NPC, not a collection of NPCs for you to filter.

 

You want something like:

 Optional<NPC> suitableNpc = getNpcs().getAll().stream().filter(npc -> npc.getHealthPercent() > 1).findFirst();
        if (suitableNpc.isPresent()) {
            suitableNpc.get().interact("examine");
        }

You may want to look a little bit into Java 8 streams before using them.

 

 

Edit:

Or better yet you can use the FilterAPI way which is native to OSBot smile.png

 

getNpcs().closest(new Filter<NPC>() {
            @[member='Override']
            public boolean match(NPC obj) {
                return obj.getHealthPercent() > 1;
            }
        }) ;

 

EntityAPI: http://osbot.org/api/org/osbot/rs07/api/EntityAPI.html

 

He was using the shorthand lambda expression, for the Filter<NPC> before.  I don't know why he changed it to what he has now.

getNpcs().closest(new Filter<NPC>() {
            @[member='Override']
            public boolean match(NPC obj) {
                return obj.getHealthPercent() > 1;
            }
        }) ;

is the same as

getNpcs().closest(npc -> npc.getHealthPercent() > 1);

@@PuppyLover101, change it back to what you had before, where you had the yellow lines.  The yellow lines just means there is a warning.  It will still compile and run.  In eclipse, you can hover over the underlined lines of code and it will tell you what the warning is.  It will also give you suggestions on how to fix it.  If you can screenshot the warning tool tip, we can help you get rid of it. 

Edited by Manner

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
  • Recently Browsing   0 members

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