Jump to content

"NPC Could not be resolved"


Recommended Posts

Posted (edited)

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. 

 

Sorry guys i helped him rewrite the script differently lul. I didn't know how to fix the issues with the way he wrote it so i showed him another way to write it and explained it to him. I told him i could be wrong though :<. It works though. Here's how his code is now

http://pastebin.com/PEeiMSfh (does the job)

 

I've told him to ask me about the parts of it he doesn't understand and i'll explain it. I did this before i read this thread btw.

 

edit: i've never made a combat script before fyi 

Edited by PlagueDoctor
Posted

Sorry guys i helped him rewrite the script differently lul. I didn't know how to fix the issues with the way he wrote it so i showed him another way to write it and explained it to him. I told him i could be wrong though :<. It works though. Here's how his code is now

http://pastebin.com/PEeiMSfh (does the job)

 

I've told him to ask me about the parts of it he doesn't understand and i'll explain it. I did this before i read this thread btw.

 

edit: i've never made a combat script before fyi 

 

6cde82a6a1e0b8e34e2c18f44ffdfb13.png

 

If the closest cow is under attack, the script will not do anything.

 

Take a look at this: http://pastebin.com/cTGie1Dq

Posted (edited)

6cde82a6a1e0b8e34e2c18f44ffdfb13.png

 

If the closest cow is under attack, the script will not do anything.

 

Take a look at this: http://pastebin.com/cTGie1Dq

if (cow != null) {
                if (cow.interact("Attack")){
                    new ConditionalSleep(5000) {
                        @[member='Override']
                        public boolean condition() throws InterruptedException {
                            return myPlayer().getInteracting() != null;
                        }
                    }.sleep();
                }

Ah i see, very nice. Sorry if i wasted anyones time by proxy. I quite enjoyed helping him cause i was learning stuff as i went aswell.

 

 

Edit:

http://pastebin.com/i9Tw935f - code is now like so.

 

Thanks for the link Manner, looks like it will work well.

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

This is very useful, i'm going to read up on this as well. Thanks for posting.

Edited by PlagueDoctor

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