1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Players with more blocks placed

Discussion in 'Development' started by DanielYTK, May 18, 2017.

  1. DanielYTK

    DanielYTK Zombie

    Messages:
    227
    So, in my plugin, every time a player is in the block on the floor, I add +1 to their respective place in the configuration, see:
    Code:
     ---
    Steve: 431.
    Alex: 125
    Mia: 654
    Vicent: 334
    ... 
    
    I wanted to have three of those who put a majority of the blocks, but I can not think of any method that I can do this.
    Any help is welcome, thank you.[/Code]
     
  2. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    If your question is finding the top three of all of them..
    Use arsort()
    PHP:
    //class extending PluginBase
    $path $this->getDataFolder()."config.yml";
    $array yaml_parse_file($path);
    arsort($array);
    $players array_keys($array);
    /**
    * If you just want the top 3 player names,
    * you can end here.
    * Top 3:
    * * $players[0]
    * * $players[1]
    * * $players[2]
    *
    * Their scores:
    * * $array[$players[0]]
    * * $array[$players[1]]
    * * $array[$players[2]]
    */

    $top3 = [];
    for(
    $i 0$i 3; ++$i){
        
    $top3[$players[$i]] = $array[$players[$i]];
    }
    /**
    $top3 = [
        "Mia" => 654,
        "Steve" => 431,
        "Vicent" => 334
    ];
    */
     
  3. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    do you have evidence of previous attempts?
     
  4. DanielYTK

    DanielYTK Zombie

    Messages:
    227
    No
     
  5. DanielYTK

    DanielYTK Zombie

    Messages:
    227
    Thanks
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.