Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Tops

Comments in 'Plugin Development' started by Vladislav, Apr 6, 2016.

  1. Vladislav
    Offline

    Vladislav New Member

    Joined:
    May 7, 2015
    Posts:
    17
    Minecraft User:
    CMEPTb5
    How to make a command with / top so that the player is displayed a message with the top 3 killers?
  2. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    Save the kills of the players, sort them and send the name to the player.
  3. Vladislav
    Offline

    Vladislav New Member

    Joined:
    May 7, 2015
    Posts:
    17
    Minecraft User:
    CMEPTb5
    How to sort from largest to smallest?
  4. minebuilder0110
    Offline

    minebuilder0110 Notable Member

    Joined:
    Dec 8, 2014
    Posts:
    485
    Minecraft User:
    Apparitional
    applqpak likes this.
  5. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Use an SQL database for saving so much data.
    applqpak likes this.
  6. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
    If there would be an tutorial ANYWHERE in the Internet how to do this with php, i would do it. BUT I don't find any
  7. Vladislav
    Offline

    Vladislav New Member

    Joined:
    May 7, 2015
    Posts:
    17
    Minecraft User:
    CMEPTb5
  8. MyNameIsTriXz
    Offline

    MyNameIsTriXz Notable Member

    Joined:
    Aug 17, 2015
    Posts:
    538
    Minecraft User:
    MyNameIsTriXz
    It depends on how you store the kills, in my minigame plugin I do it like this to get thr best 3 players:

    PHP:

    $this
    ->kills = [];

    onKill...{

    if(isset(
    $this->kills[$player->getName()])){
    $this->kills[$player->getName()] += 1;

    }else {

    $this->kills[$player->getName()] = 1;
    }

    When you want to display the top kills:

    arsort($this->kills);

    // arsort sorts an array by its values
    // note dont do $this->kills = arsort($this->kills);

    Now you can just do that:

    $bests = [];
    $n 0;

    foreach(
    $this->kills as $playername => $kills){

    $n++;

    $bests[$n]["Name"] = $playername;
    $bests[$n]["Kills"] = $kills;

    }

    echo 
    "The best player is ".$bests[0]["Name"];

    But just check with isset whether those keys are set.
    Anyways use MySQLonly as a starter I am recommending to do it this way.


    }


    }

    Last edited: Apr 9, 2016
    Vladislav likes this.
  9. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Are you sure you want to load 200000 data into an array and sort them every time, on the main thread?
    Primus, KubixQ and applqpak like this.
  10. KubixQ
    Offline

    KubixQ Active Member

    Joined:
    Sep 13, 2015
    Posts:
    85
    Minecraft User:
    KubixQ
    There's app in Google Play named Learn SQL.
    applqpak likes this.
  11. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    Indeed
    PHP:
    $this->db->query("SELECT `kills`,`deaths` FROM `server`.`players` WHERE `name` LIKE '".$name."' ORDER BY `kills` DESC;");
    applqpak likes this.
  12. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
    Hmm... Don't have android
  13. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    That doesn't deny the fact that there is a tutorial which shows how to do that!
    applqpak likes this.
  14. Vladislav
    Offline

    Vladislav New Member

    Joined:
    May 7, 2015
    Posts:
    17
    Minecraft User:
    CMEPTb5
    Thanks
  15. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    PHP:
    $this->kills[$player->getName()] .= 1;
    Did you mean
    PHP:
    $this->kills[$player->getName()] += 1;
  16. MyNameIsTriXz
    Offline

    MyNameIsTriXz Notable Member

    Joined:
    Aug 17, 2015
    Posts:
    538
    Minecraft User:
    MyNameIsTriXz
    It depends on his server, when you want to start that, you mostly start with files and then go to MySQL and other database saving methods. Anyways, I mentioned that this code is for beginners.
  17. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    It is never good to ever risk saving a possibly enormous amount of data in memory.

    Even if you don't use an SQL database, you still don't need to load all the data. You just update the top 5 kills every time the kills is updated, as described in this post: https://forums.pocketmine.net/threads/how-to-make-leaderboards-with-this-code.15490/#post-150481

    Hmm... I assume you have browser?

    http://dev.mysql.com/doc/refman/5.7/en/
    Tim // robske Büba and applqpak like this.

Share This Page

Advertisement