Jump to content

"NPC Could not be resolved"


PuppyLover101

Recommended Posts

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

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

Link to comment
Share on other sites

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