Jump to content

"NPC Could not be resolved"


PuppyLover101

Recommended Posts

Make sure you are using the java 1.8 compiler, so that it supports lambda expressions. http://stackoverflow.com/questions/22544064/java-8-lambdas-dont-work-everything-else-from-java-8-works-though

I don't have 1.8 tho.. I can only see 1.7

 

Edit: downloading the update now, ill let u know how it goes

Edited by PuppyLover101
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

 

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).

Link to comment
Share on other sites

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
Link to comment
Share on other sites

 

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 

Link to comment
Share on other sites

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