Jump to content

How to check if there is players nearby?


kerklais

Recommended Posts

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

 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?

Link to comment
Share on other sites

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

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

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