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

How to make leaderboards with this code?

Comments in 'Plugin Development' started by CaptainKenji17, Feb 24, 2016.

  1. CaptainKenji17
    Offline

    CaptainKenji17 Active Member

    Joined:
    Apr 22, 2014
    Posts:
    252
    Minecraft User:
    CaptainKenji17
    How to make leaderboards with this code?

    PHP:
    $this->PlayerFile = new Config($this->getDataFolder()."Players/".$ign."_Stats.yml"Config::YAML);

    if(
    $this->PlayerFile->get("Kills") > && $this->PlayerFile->get("Deaths") > 0){
    On command this thing worked by checking your own stats and the code is

    PHP:
        public function onCommand(CommandSender $senderCommand $cmd$label, array $args) {
            
    $name $sender->getName();
            
    $ign $sender->getName();

            
    $this->PlayerFile = new Config($this->getDataFolder()."Players/".$ign."_Stats.yml"Config::YAML);
          
            if(
    strtolower($cmd->getName()) === 'stats'){

              if(
    $sender->hasPermission("mcpemmo.stats")) {


                if(
    $this->PlayerFile->get("Kills") > && $this->PlayerFile->get("Deaths") > 0){


               
    $sender->sendMessage("§8> §l§7YOUR STATS M8 §8<"."\n§8> §5Kills§8: §c".$this->PlayerFile->get("Kills")."\n§8> §5Deaths§8: §c".$this->PlayerFile->get("Deaths")."\n§8> §5KDR§8: §c".round($this->PlayerFile->get("Kills")/$this->PlayerFile->get("Deaths"), 2));
            } else {
              
    $sender->sendMessage("§8> §l§7YOUR STATS M8 §8<"."\n§8> §5Kills§8: §c".$this->PlayerFile->get("Kills")."\n§8> §5Deaths§8: §c".$this->PlayerFile->get("Deaths")."\n§8> §5KDR§8: §c".round($this->PlayerFile->get("Kills")/$this->PlayerFile->get("Deaths"), 2)/*."\n§8> ".$time*/);


                }
              }
            }
          }
    I think its something asort, how to do it?
    Last edited: Feb 24, 2016
  2. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Use an SQLite3 database. It is much better and easier if you want collective management on your data.
  3. CaptainKenji17
    Offline

    CaptainKenji17 Active Member

    Joined:
    Apr 22, 2014
    Posts:
    252
    Minecraft User:
    CaptainKenji17
    I'll try soon, can you give me a code here saying "TOP KILLERS\n1. name\n2.name..." up to 10? when you type a command /top
  4. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    And I was telling you that not using an SQL-family database would make storing top killers much harder...

    Well, without using SQL it is still possible. You can create a separate array for storing the top 10 players. Then if you refresh the top 10 list every time a list entry changes, it will be more efficient.
    Try this every time an entry updates:
    1. Merge new entry with existing kills
    2. Sort the array with rsort()
    3. Store the top 10 entries using array_slice.

    I won't give you code directly, but here is an example of how to do it: https://gist.githubusercontent.com/...ac7b79ce20a3eafc9d9c08a0c27f9/SKC_Rewrite.php especially search "topkill".
    Although it is written in the old API, what matters here is the PHP functions and algorithm used, so you should still be able to understand it.

    Right, you asked me for code, I gave you code. Just that you cannot use the code directly, but if you can copy with understanding what it does, you should have no difficulties understanding how the updateTopKills() function my my code works.
    CaptainKenji17 likes this.

Share This Page

Advertisement