Jump to content

Check for players in your area


Iwin

Recommended Posts

	public boolean checkforPlayers(int area) {
		java.util.List<Player> playerss = players.getAll();
		for (Player p : playerss) {
			if (myPlayer().getArea(area).contains(p) && !p.getName().equals(myPlayer().getName())) {
				return true;
			}
		}
		return false;
	}

Returns true if there's players around your area. (excluding yourself)

I use this generally like this:

 

if(checkforPlayers(7) && random(0,25) == 0){
/* do world hop*/
}
  • Like 1
Link to comment
Share on other sites

Nevermind, I take my suggestion back. After some testing it appears that filters are highly inefficient (300 ms vs 3000ms for 10000 loops)

 

Do remember though, at most there can be 2000 players on and therefore can at most be 2000 loops for it. And worst case probably like ~600 anyway. It looks neat asf so worth.

  • Like 2
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...