Jump to content

Check for players in your area


Recommended Posts

Posted

	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
Posted

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

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