Making signs that display amount of players in selected area?

Discussion in 'Plugin Development' started by w84u2cy, Sep 3, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    w84u2cy

    Can anyone help me make a plugin that displays the amount of players in a selected area?
    Thanks!
    Ben

    Bump! Sry!

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 4, 2016
  2. This shouldn't be too hard using WorldGuard. Keep a reference to the location of the sign, then run a syncRepeatedTask that gets all players in that world and counts how many are inside the region, pasting it to the sign.
     
  3. Offline

    w84u2cy

    I'm not very good at using world guard tho....
    I'll check google

    Anyone?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 4, 2016
  4. Offline

    FozZeW

    Or use world edit.
    1) create world edit selection
    2) save min and max point of selection
    3) onEnable load that selection and make it to region
    4) on PlayerMoveEvent make loop that loops through all players and checks if player is in that region
    (There is simple method in world edit for checking if player is in region) make integer and add 1 to it everytime loop says that player is in region
    5) And there you have it, your amount of players in your region and u can do anything with that integer now

    Any questions ? :D
     
  5. Offline

    TheSmallBones

    Here is some code from a project of mine. You need a POS1 and a POS2. You can hard core it in or you can have it in your config file. So pretty much you would do a for statement and get all the players on the server and then run this method with their name:
    Code:
    public boolean inArea(Location location1, Location location2, Location playerLocation){
            if((playerLocation.getBlockX() >= location1.getBlockX() && playerLocation.getBlockX() <= location2.getBlockX()) || (playerLocation.getBlockX() <= location1.getBlockX() && playerLocation.getBlockX() >= location2.getBlockX())){
                if((playerLocation.getBlockZ() >= location1.getBlockZ() && playerLocation.getBlockZ() <= location2.getBlockZ()) || (playerLocation.getBlockZ() <= location1.getBlockZ() && playerLocation.getBlockZ() >= location2.getBlockZ())){
                    return true;
                }
            }
            return false;
        }
    And then inside your for statement you would have an int increase if(inArea(p.getLocation(), pos1, pos2)){ int++: }

    and then once it's done set the sign text to the int!
     
  6. Offline

    FozZeW

    pfft, it would be easier with world edit :D
     
  7. Offline

    w84u2cy

    Could you give me the commands on WE?
    And help me with the code?
     
  8. Offline

    TheSmallBones

    If you want to make your plugin have a dependency, go ahead.
     
  9. Offline

    w84u2cy

    Can anyone give me a straightforward answer pls?
     
  10. Offline

    TheSmallBones

    My answer literally gave you the code...
     
  11. Offline

    w84u2cy

    Sry but I don't really understand what to do with it :/
     
  12. Offline

    TheSmallBones

    Code:
    public void updateSign(){
    int i = 0;
    for(Player P : Bukkit.getOnlinePlayers()){
    if(inArea(P.getLocation(), YOUR_SIGN_COORDS.add(-10, 0, -10, YOUR_SIGN_COORDS.add(10, 0 , 10)))){
    i++;
    }
    }
    //code to set sign line to i
    }
     
     
     
    public boolean inArea(Location location1, Location location2, Location playerLocation){
            if((playerLocation.getBlockX() >= location1.getBlockX() && playerLocation.getBlockX() <= location2.getBlockX()) || (playerLocation.getBlockX() <= location1.getBlockX() && playerLocation.getBlockX() >= location2.getBlockX())){
                if((playerLocation.getBlockZ() >= location1.getBlockZ() && playerLocation.getBlockZ() <= location2.getBlockZ()) || (playerLocation.getBlockZ() <= location1.getBlockZ() && playerLocation.getBlockZ() >= location2.getBlockZ())){
                    return true;
                }
            }
            return false;
        }
     
  13. Offline

    w84u2cy

    Cool! Thanks!

    Ok 1 more thing,
    At your sign coords, do i put where the sign is ( X,Y)
    And also what is code to set line i?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 4, 2016
  14. Offline

    TheSmallBones

    Well you would probably have the sign coords as a global variable or loaded in from your config, then you add 10 and 10 to it and save that then add -10 and -10 to it then save that as a location, then run inArea with those parameters. Also the code to set the line to i is easily found on Google or the JavaDocs. You need to cast it to BlockState I believe.
     
  15. Offline

    w84u2cy

    Ok...I'm sorry for being a noob but...
    What do i put in YOUR_SIGN_COORDS....

    And i have no idea what line i is...
     
  16. Offline

    TheSmallBones

    Okay i is the amount of players found nearby. So you would set the sign text to i. YOUR_SIGN_COORDS is LITERALLY YOUR SIGN COORDINATES!!
     
Thread Status:
Not open for further replies.

Share This Page