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

voting for a player and counting highest voted person

Comments in 'Plugin Development' started by Kabluinc, Aug 20, 2016.

  1. Kabluinc
    Offline

    Kabluinc New Member

    Joined:
    Mar 2, 2016
    Posts:
    29
    Minecraft User:
    Kabluinc
    Hi

    I would like some help on adding this to my plug in

    when a player does /vote (player) good it adds +1 next to their name in votes.yml and if a player does /vote (player) bad it reduces the number -1

    after that what would the code be to count through and find the player with the highest vote and broadcast (player) had the most votes

    Sorry if this doesn't meet with the thread rules but I really really need some help from someone who knows such code for my need

    Thank you very very much for helping!
  2. JonsMC
    Offline

    JonsMC Active Member

    Joined:
    Jul 26, 2016
    Posts:
    107
    Minecraft User:
    JonsMC
    what did you add to your code already, can i see it?
  3. SOFe
    Offline

    SOFe Banned

    Joined:
    May 28, 2016
    Posts:
    386
    Minecraft User:
    Herobrine
    Use an SQLite3 database.

    Consider this thread [IMPROVEMENT]Use SQLite to improve your plugins! by @Humerus. It is written in the format of the old API, and its purpose is kicking players (you didn't state your purpose), but assuming that you are following the new posting guidelines, you are looking for ideas how to implement this, not the exact code to copy, so this thread should be enough for what you want.
    applqpak likes this.
  4. Kabluinc
    Offline

    Kabluinc New Member

    Joined:
    Mar 2, 2016
    Posts:
    29
    Minecraft User:
    Kabluinc
    @JonsMC well iv been trying to create a build battle plugin for pocketmine a long time now and its 90% functional. All it needs is a viting system where players can vote good (+1) or bad (-1) at others builds and at a specific time the code shud count the votes and broadcast player with highest vote as winner

    I could upload the plugins source to github so u cud help me or do u know anyone that can know how to do this

    Many thanks
  5. JonsMC
    Offline

    JonsMC Active Member

    Joined:
    Jul 26, 2016
    Posts:
    107
    Minecraft User:
    JonsMC
    Create a temporary .txt file and store player vote in it while match is started?, when match end, unlink that file
  6. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    PHP:
    protected $votes = [];

    public function 
    addVote(Player $player) {
       
    $this->votes[$player->getName()]++;
    }

    public function 
    removeVote(Player $player) {
       
    $this->votes[$player->getName()]--;
    }

    public function 
    getVotes(Player $player) {
       return 
    $this->votes[$player->getName()];
    }
    Do not use these functions as they are for illustrative purposes only
  7. JonsMC
    Offline

    JonsMC Active Member

    Joined:
    Jul 26, 2016
    Posts:
    107
    Minecraft User:
    JonsMC
    btw, will variables Be gone when server stop? XP
    MCPEPIG likes this.
  8. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    Yes it will be. As far as I can tell, he is making a mini-game, Build battle to be precise, and do you really think those votes will be necessary after match has ended?

    But if someone needs to save these votes, you can do
    PHP:
    # Let's use some help of Config class
    (new Config("votes.yml"Config::YAML$this->votes))->save();
    SOFe likes this.
  9. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    SQLite3 is faster than YAML?
  10. Ragnok1234
    Offline

    Ragnok1234 Active Member

    Joined:
    Jul 18, 2016
    Posts:
    53
    Minecraft User:
    Ragnok123
    No
  11. Salmon__GER
    Offline

    Salmon__GER New Member

    Joined:
    Aug 6, 2015
    Posts:
    10
    Minecraft User:
    SalmonDE
  12. SOFe
    Offline

    SOFe Banned

    Joined:
    May 28, 2016
    Posts:
    386
    Minecraft User:
    Herobrine
    I am referring to a :memory: SQLite3 database, which means that it will not be saved in any files, so it shall be much more efficient than YAML. SQLite3 has native code that manages contents in a table of data. It is much more efficient than managing data in PHP code (assuming you are managing a great amount of data). Moreover, if you are familiar with both ways of managing data, SQL-based databases are much more convenient than using an array because of how it internally manages indexes. See this example: https://github.com/LegionPE/LegionP...rc/legionpe/theta/classic/TeleportManager.php

Share This Page

Advertisement