Players up and down

Discussion in 'Spigot Plugin Development' started by --TOMAS--, May 18, 2016.

  1. How to get players up and down there is another player?
     
  2. Can you explain in more detail what you need help with?
     
    • Agree Agree x 1
  3. I want a command, for example, say that there are players up and down my. The preferred example scoreboard.
     
  4. Best english i have ever read. :confused:
     
  5. I did my ultimate best, but I still don't understand what you mean :p
     
    • Like Like x 1
    • Winner Winner x 1
  6. I want to get through a command players have up and down. Like the scoreboard of TntRun of Hypixel.
     
  7. He wants a command that displays all the players above and below you in a scoreboard. This is simple, but would overwrite any other scoreboard you have set up.

    Also, I hope you plan on writing this yourself, this isn't a place to request.
     
  8. OMG, so you wanna know how many players are below you (as in the Y-coordinate lower than yours) and how many players are above you (as in the Y-coordinate higher than yours)?

    Well, there you have the answer ^

    First, get player's Y-coordinate.
    Code (Text):
    double y = p.getLocation().getY(); //please note that you can also use: int y = p.getLocation().getBlockY(); if you'd like to compare whether they're above/below based on the block
    we need two int variables (int above and int below) and assign them the value: 0
    Code (Text):
    int above = 0;
    int below = 0;
    int same = 0;
    Loop through all online players
    Code (Text):
    for (Player online : Bukkit.getOnlinePlayers()) {
      //we're gonna do some stuff here  
    }
    Then we have to compare "online"'s Y-coordinate to your Y-coordinate (weather it's below, above, or the same). Again, you can use: Player#getBlockY();
    Code (Text):
    for (Player online : Bukkit.getOnlinePlayers()) {
      if(online.getLocation().getY() < y) {
        below++;
      } else if(online.getLocation().getY() > y) {
        above++;
      } else {
        same++;
      }
    }
    Now the variables
    • below: would equal all players below the player
    • above: would equal all players below the player
    • same: would equal all the players at the same [ground] level as the player

    EDIT #1:
    Code (Text):
    double y = p.getLocation().getY();

    int above = 0;
    int below = 0;
    int same = 0;

    for (Player online : Bukkit.getOnlinePlayers()) {
      if(online.getLocation().getY() < y) {
        below++;
      } else if(online.getLocation().getY() > y) {
        above++;
      } else {
        same++;
      }
    }
    p.sendMessage("There are " + above + " players above you");
    p.sendMessage("There are " + below+ " players below you");
    p.sendMessage("There are " + same + " players at the same level as you");
     
  9. Only this? Thanks you :D
     
  10. Should be about that yes. That's how you'd get the amounts, but not how you'd create THAT scoreboard though.