May 31, 20169 yr I'm trying to make my script log out when any player is in my vicinity. I think I have to use the "getAll()" method in the Players class in the API to do this, but I can't figure out how to write it. Also, will the list be true, full, or something else if there is another player nearby? Thanks.
May 31, 20169 yr for (Player p : methods.getPlayers().getAll()) { if (p.isVisible() || p.getPosition().distance(methods.myPlayer().getPosition()) < 10) { // OH NOES } } } where methods is an instance of MethodProvider note: i did not test this Edited May 31, 20169 yr by Pure_
May 31, 20169 yr Author Idk how MethodProvider works so i took out the "methods.". The code was also picking up my character and going into the if statement so I changed the if condition to if ((p.getPosition().distance(myPlayer().getPosition()) > 1) && (p.getPosition().distance(myPlayer().getPosition()) < 20) ) Thanks! Edited May 31, 20169 yr by TheGreatPani
May 31, 20169 yr Idk how MethodProvider works so i took out the "methods.". The code was also picking up my character and going into the if statement so I changed the if condition to if ((p.getPosition().distance(myPlayer().getPosition()) > 1) && (p.getPosition().distance(myPlayer().getPosition()) < 20) ) Thanks! //why not !p.getname#equals(your acc)
May 31, 20169 yr for (Player p : methods.getPlayers().getAll()) { if (p.isVisible() || p.getPosition().distance(methods.myPlayer().getPosition()) < 10) { // OH NOES } } } where methods is an instance of MethodProvider note: i did not test this accully u cant use this method for do, yuo must use recurse method to loop through for player
May 31, 20169 yr accully u cant use this method for do, yuo must use recurse method to loop through for player That method works fine, he just might want to check that the player != myPlayer Edited May 31, 20169 yr by Explv
May 31, 20169 yr // Set maximum distance. private final int maximumDistance = 12; /* Create filter. Player must: - Not be null. - Exist. - Be within the maximum distance from my player. */ private final Filter<Player> filter = player -> player != null && player.exists() && (player.getPosition().distance(myPlayer.getPosition()) < maximumDistance ); // ... /* To check if one or more players are nearby: Apply filter to Players instance. Check if the result set is greater than 1. (myPlayer itself will always be part of the result set). */ if(getPlayers().filter(filter).size() > 1) { // There are players nearby. } // ... /* To get the amount of players nearby: Apply filter to Players instance. Subtract 1 from the result set. (myPlayer itself will always be part of the result set). */ int nearby = getPlayers().filter(filter).size() - 1; Edited May 31, 20169 yr by Botre
May 31, 20169 yr I'm trying to make my script log out when any player is in my vicinity. I think I have to use the "getAll()" method in the Players class in the API to do this, but I can't figure out how to write it. Also, will the list be true, full, or something else if there is another player nearby? Thanks. If you want to check if a player is less than a certain distance away, you can use: private boolean isOtherPlayerWithinDistance(final int distance) { for(final Player player : getPlayers().getAll()) { if(player != myPlayer() && player.getPosition().distance(myPosition()) < distance) { return true; } } return false; } Or you can use a filter: private boolean isOtherPlayerWithinDistance(final int distance) { return !getPlayers().filter(player -> player != myPlayer() && player.getPosition().distance(myPosition()) < distance).isEmpty(); } Otherwise you can just check the size of getPlayers().getAll() private boolean isOtherPlayerNearby() { return getPlayers().getAll().size() > 1; } Edited May 31, 20169 yr by Explv
Create an account or sign in to comment