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.

Method to define closest NPC that isn't in combat?

Featured Replies

Probably super simple I'm just not sure. Been a while since I've been on here. Also my script keeps getting stuck saying there are arrows to be picked up but there aren't. Any ideas why?

 

73ef1fc6c7bdf3b5072d822f2752bf53.png

	public boolean arrowsPresent() {
		if (getGroundItems().closest(arrowType) != null) {
			return true;
		}
		return false;
	}

Edited by Paradox68

Probably super simple I'm just not sure. Been a while since I've been on here.

I would use a filter like this:

Filter<NPC> monsterFilter = new Filter<NPC>() {
    @Override
    public boolean match(NPC n) {
        if (n.getId() != monsterID)
            return false;
        if(!n.getName().equals(monsterName))
            return false;
        if(n.isUnderAttack())
            return false;
        return true;
    }
};

then you can just say: 

NPC monster = getNpcs().closest(monsterFilter);

Did that help?

Edited by AresScripts

  • Author

I would use a filter like this:

Filter<NPC> monsterFilter = new Filter<NPC>() {
    @Override
    public boolean match(NPC n) {
        if (n.getId() != monsterID)
            return false;
        if(!n.getName().equals(monsterName))
            return false;
        if(n.isUnderAttack())
            return false;
        return true;
    }
};

then you can just say: 

NPC monster = getNpcs().closest(monsterFilter);

Did that help?

 

 

A lot actually, thanks dude. Not to be mr. stupid but what's this about?

9c66c2a47fc882b785b2994d47763f00.png

Edited by Paradox68

A lot actually, thanks dude. Not to be mr. stupid but what's this about?

9c66c2a47fc882b785b2994d47763f00.png

I haven't used eclipse in a while but i remember that being not necessary to fix. Warnings usually aren't an actual problem(someone correct me if im wrong)

Edited by AresScripts

I would use a filter like this:

Filter<NPC> monsterFilter = new Filter<NPC>() {
    @Override
    public boolean match(NPC n) {
        if (n.getId() != monsterID)
            return false;
        if(!n.getName().equals(monsterName))
            return false;
        if(n.isUnderAttack())
            return false;
        return true;
    }
};

then you can just say: 

NPC monster = getNpcs().closest(monsterFilter);

Did that help?

 

 

Or you could just do:

NPC monster = getNpcs().closest(npc -> npc.getName().equals("Cow") && !npc.isUnderAttack());

A lot actually, thanks dude. Not to be mr. stupid but what's this about?

9c66c2a47fc882b785b2994d47763f00.png

 

Just suppress it, the warning is for an operation that is potentially unsafe, but in this case we know it is fine.

@SuppressWarnings("unchecked") 
NPC monster = getNpcs().closest(npc -> npc.getName().equals("Cow") && !npc.isUnderAttack());

Also with regards to your arrow method, it can be simplified to:

public boolean arrowsPresent() {
    
    return getGroundItems().closest(arrowType) != null;
}

And it should work fine, it is probably an issue somewhere else in your code.

Edited by Explv

Or you could just do:

NPC monster = getNpcs().closest(npc -> npc.getName().equals("Cow") && !npc.isUnderAttack());

Just suppress it, the warning is for an operation that is potentially unsafe, but in this case we know it is fine.

@SuppressWarnings("unchecked") 
NPC monster = getNpcs().closest(npc -> npc.getName().equals("Cow") && !npc.isUnderAttack());

Also with regards to your arrow method, it can be simplified to:

public boolean arrowsPresent() {
    
    return getGroundItems().closest(arrowType) != null;
}

And it should work fine, it is probably an issue somewhere else in your code.

Ah. I need to study up on lambda expressions :o

Ah. I need to study up on lambda expressions ohmy.png

 

 

I found your Filter to be written a little oddly as well tongue.png

 

Why would you do:

Filter<NPC> monsterFilter = new Filter<NPC>() {
    @Override
    public boolean match(NPC n) {
        if (n.getId() != monsterID)
            return false;
        if(!n.getName().equals(monsterName))
            return false;
        if(n.isUnderAttack())
            return false;
        return true;
    }
};

 when you could just do:

Filter<NPC> monsterFilter = new Filter<NPC>() {
    @Override
    public boolean match(NPC n) {
        return n.getName().equals("Cow") && !n.isUnderAttack();
    }
};

But yeah, lambdas make everything more simple anyway ^_^

Edited by Explv

I found your Filter to be written a little oddly as well tongue.png

 

Why would you do:

Filter<NPC> monsterFilter = new Filter<NPC>() {
    @Override
    public boolean match(NPC n) {
        if (n.getId() != monsterID)
            return false;
        if(!n.getName().equals(monsterName))
            return false;
        if(n.isUnderAttack())
            return false;
        return true;
    }
};

 when you could just do:

Filter<NPC> monsterFilter = new Filter<NPC>() {
    @Override
    public boolean match(NPC n) {
        return n.getName().equals("Cow") && !n.isUnderAttack();
    }
};

But yeah, lambdas make everything more simple anyway happy.png

Even though that takes up less lines of code, I like to only do one "filter" per if statement because its easier to debug for me.

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.