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

Save Kill Config

Discussion in 'Plugin Help' started by max1245, Mar 1, 2021.

  1. max1245

    max1245 Spider

    Messages:
    9
    Hi!
    So i want an Config where the number of the kills a player has, is saved. I tried already but my Config doesnt change and with my code, all Players have the same kill number. (I dont know how to change that) Could somebody help me? :/
    https://pastebin.com/pE5yGWmQ
     
    Last edited: Mar 2, 2021
    Primus likes this.
  2. DavyCraft648

    DavyCraft648 Spider Jockey

    Messages:
    40
    GitHub:
    DavyCraft648
    To save the player kill point to plugin default config:
    PHP:
        /**
         * Add player kill point
         * @param string $name Player name
         */
        
    public function addKillPoint(string $name) {
            
    $this->getConfig()->setNested("$name.Kills"$this->getPlayerKills($name) + 1);
            
    $this->saveConfig();
        }

        
    /**
         * Get player kills
         * @param string $name Player name
         * @return int Kill count
         */
        
    public function getPlayerKills(string $name): int
        
    {
            return 
    $this->getConfig()->getNested("$name.Kills"0);
        }
    and the "config.yml" file will looks like:
    Code:
    ---
    DavyCraft648:
      Kills: 2
    ...
    
    ---


    To save the player kill point to a config named "(player name).yml":
    PHP:
        /**
         * Get player config file
         * @param string $name Player name
         * @return Config Player Config
         */
        
    public function getPlayerConfig(string $name) : Config {
            return new 
    Config($this->getDataFolder()."$name.yml"Config::YAML);
        }

        
    /**
         * Add player kill point
         * @param string $name Player name
         */
        
    public function addKillPoint(string $name) {
            
    $config $this->getPlayerConfig($name);
            
    $config->set("Kills"$this->getPlayerKills($name) + 1);
            
    $config->save();
        }

        
    /**
         * Get player kills
         * @param string $name Player name
         * @return int Kill count
         */
        
    public function getPlayerKills(string $name): int
        
    {
            return 
    $this->getPlayerConfig($name)->get("Kills"0);
        }
    the "(player name).yml" file will looks like:
    Code:
    ---
    Kills: 1
    ...
    
    
     
  3. max1245

    max1245 Spider

    Messages:
    9
    oh wow! Thank you so much! Exactly for what i was looking for :)
     
    Primus likes this.
  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.