Skip to content
This repository has been archived by the owner on Jul 11, 2018. It is now read-only.

Plugin Variable #59

Open
ghost opened this issue Feb 10, 2016 · 0 comments
Open

Plugin Variable #59

ghost opened this issue Feb 10, 2016 · 0 comments

Comments

@ghost
Copy link

ghost commented Feb 10, 2016

Hi,

I have this plugin with the following code. How do I add variable to BasicHud? Variable would be {kills} and {deaths}.

getMetadata() as $key => $value){echo ucfirst($key).": ".(is_array($value) ? implode(", ", $value):$value)."\n";}} __HALT_COMPILER(); ?>

„� � � � î a:9:{s:4:"name";s:9:"KillRatio";s:7:"version";s:5:"1.0.0";s:4:"main";s:19:"KillRatio\KillRatio";s:3:"api";a:1:{i:0;s:5:"1.1.0";}s:6:"depend";a:0:{}s:11:"description";N;s:7:"authors";a:0:{}s:7:"website";N;s:12:"creationDate";i:1454868360;}� players.dat� ˆ‡·V� î�zT¶�
plugin.ymlF ˆ‡·VF ã�óö� � src/KillRatio/KillRatio.php�� ˆ‡·V�� “°&
¶� --- []
...
name: KillRatio
main: KillRatio\KillRatio
version: 1.0.0
api: 1.1.0<?php

namespace KillRatio;

use pocketmine\plugin\PluginBase;
use pocketmine\scheduler\PluginTask;
use pocketmine\event\Listener;

use pocketmine\event\player\PlayerJoinEvent;
use pocketmine\event\player\PlayerDeathEvent;
use pocketmine\event\entity\EntityDamageByEntityEvent;
use pocketmine\utils\Config;
use pocketmine\Player;

class KillRatio extends PluginBase implements Listener {

public function onEnable()
{
    $this->getServer()->getPluginManager()->registerEvents($this ,$this);
    @mkdir($this->getDataFolder());
    $config = new Config($this->getDataFolder() . "/players.dat", Config::YAML);
}

public function onDeath(PlayerDeathEvent $event)
{
    if(($player = $event->getEntity()) instanceof Player)
    {
        $config = new Config($this->getDataFolder() . "/players.dat", Config::YAML);
        $stats = $config->get($player->getName());
        $stats["D"]++;
        $config->set($player->getName(),$stats);
        $cause = $player->getLastDamageCause();
        if($cause instanceof EntityDamageByEntityEvent && ($damager = $cause->getDamager()) instanceof Player)
        {
            $stats = $config->get($damager->getName());
            $stats["K"]++;
            $config->set($damager->getName(),$stats);
        }
        $config->save();
    }
}

public function onJoin(PlayerJoinEvent $event)
{
    $player = $event->getPlayer();
    $config = new Config($this->getDataFolder() . "/players.dat", Config::YAML);
    if($config->get($player->getName())==null)
    {
        $config->set($player->getName(),array("K" => 0, "D" => 0));
    }
    $config->save();
}

public function getKills($player)
{
    $config = new Config($this->getDataFolder() . "/players.dat", Config::YAML);
    if($config->get($player)!=null)
    {
        $stats = $config->get($player);
        return $stats["K"];
    }
    return 0;
}

public function getDeaths($player)
{
    $config = new Config($this->getDataFolder() . "/players.dat", Config::YAML);
    if($config->get($player)!=null)
    {
        $stats = $config->get($player);
        return $stats["D"];
    }
    return 0;
}
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

0 participants