Jump to content

How to check if there is players nearby?


Recommended Posts

Posted
4 minutes ago, GPSwap said:

Player closest = getPlayers().closest(p -> p != null && !p.equals(myPlayer()));

closest is != null if there is a player within detectable distance (just about the size of the minimap)

This should actually work quicker than my example.

Adding a lil extra to filter by predefined distance

Player closest = getPlayers().closest(p -> p != null && !p.equals(myPlayer()) && myPlayer.getArea(5).contains(p));

 

  • Like 1
Posted
 public int onLoop() throws InterruptedException {
        if (AREA.contains(myPlayer())) {
            Player closest = getPlayers().closest(p -> p != null && !p.equals(myPlayer()));
            if (closest !=null)
                log("Hopping....");
                 getWorlds().hopToP2PWorld();
                 wait(5000); //freezes here...?
        }else {
             log("Walking");
             if (getWalking().walk(AREA));
             new ConditionalSleep(3000, 1000) {
                 @Override
                 public boolean condition() throws InterruptedException {
                     return (AREA.contains(myPlayer()));
                 }
             }.sleep();
                        }
        return 100;

I tested those and they work. But now I'm trying to compound that script with world hopping.. Any help?

Posted
3 hours ago, nosepicker said:

This should actually work quicker than my example.

Adding a lil extra to filter by predefined distance


Player closest = getPlayers().closest(p -> p != null && !p.equals(myPlayer()) && myPlayer.getArea(5).contains(p));

 

You're misusing getArea:

  1. You're creating a new Area object just to test whether someone is inside of it. What a total waste.
  2. You're creating that new Area object for each player you check.

Additionally, the null check is redundant as OSBot won't pass you null values to begin with, and you should cache myPlayer() somewhere, as that's likely a function that interfaces with the game to grab your player information. You should only have to grab it once for the duration of your checking. Otherwise, it's just inefficient.

  • Like 2
Posted
30 minutes ago, liverare said:

I'm guessing you're trying to find players who are nearby you? If so:


private List<Player> getPlayersNearby(int distance) {
	final Player me = myPlayer();
	return players.filter(p -> !me.equals(p) && me.getPosition().distance(p) <= distance);
}

 

Yep or actually trying to check if there's any players nearby if there is the script will hop.. 

Posted
4 hours ago, GPSwap said:

Player closest = getPlayers().closest(p -> p != null && !p.equals(myPlayer()));

closest is != null if there is a player within detectable distance (just about the size of the minimap)

or simply !getPlayers().getAll().isEmpty()

Edit: to account for my player just check if size == 1

  • Like 3

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