Jump to content
View in the app

A better way to browse. Learn more.

OSBot :: 2007 OSRS Botting

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

"NPC Could not be resolved"

Featured Replies

  • Author

 

Yellow lines are warnings.

 

Also that could be simplified to:

NPC cow = getNpcs().closest(npc -> npc.getName().startsWith("Cow") && npc.isAttackable() && cowArea.contains(npc));

 

Hmmm thanks, but it shows this still:- http://i.imgur.com/t8rwK0l.png

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

  • Author

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

 

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

  • Author

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

 

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 

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

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.