Solved Slap me! Numbers and Math :O

Discussion in 'Plugin Development' started by Whats for Today, Nov 9, 2012.

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

    Whats for Today

    Yes, please slap me. Right across the face, anyways so lets begin another simple question which should be easy to answer :I

    I have this:
    Code:text
    1. int rp = new Random().nextInt(getServer().getOnlinePlayers().length);
    2. Player p = getServer().getOnlinePlayers()[rp];


    What I want to do with this is basically... get half of the online player. Difficult huh, any helps is always appreciated and any slaps are deserved.
     
  2. Offline

    cman1885

    Code:
    for(int i = 0; i<getServer().getOnlinePlayers().length/2;i++){
      Player p = getServer().getOnlinePlayers()[i];
      ... 
    }
     
    
     
  3. Offline

    Kanlaki101

    If there's 30, you want 15?

    getServer().getOnlinePlayers().length / 2?

    EDIT: Ninja'd.
     
  4. Offline

    Whats for Today

    Thank you <3, now if I would like to have 6 people online before it is allowed to do this. So, it will not do this if there are any less than 6 people online. I should just go back and learn math for java. -.- (<---- Best idea I have ever had).
     
  5. Offline

    cman1885

    Only run the loop if the length of the online players is 6 or higher. Just put the whole thing in an if.
     
  6. Offline

    Whats for Today

    Okay, thank you again:

    I put it in the if statement:
    Code:java
    1. int onp = getServer().getOnlinePlayers().length;
    2. if(onp <= 6){
     
  7. Offline

    darkmage0252


    its >= the way you put it only allows it if there are less than or equal to 6.
     
  8. Offline

    Whats for Today

    Pshhh, semantics, thank you :]
     
Thread Status:
Not open for further replies.

Share This Page