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

Player kills and deaths

Comments in 'Plugin Development' started by NycuRO, Apr 23, 2016.

  1. NycuRO
    Offline

    NycuRO Active Member

    Joined:
    Oct 19, 2015
    Posts:
    64
    Minecraft User:
    NycuRK
    What code need use for calculate player kills and deaths ?

    I'm using :

    public function onDeath(PlayerDeathEvent $event){
    $entity = $event->getEntity();
    $kills = $event->$entity->get($name);
  2. korado531m7
    Offline

    korado531m7 Active Member

    Joined:
    Apr 4, 2015
    Posts:
    158
    Minecraft User:
    korado531m7
    PHP:
    public function PlayerDeath(PlayerDeathEvent $event){
                
    $cause $event->getEntity();
                
    $name $cause->getName();
                
    $this->death[$name] = $this->death[$name]+1//Add Death
                
    if($cause instanceof EntityDamageByEntityEvent){
                    if(
    $killers instanceof Player){
                        
    $killers $cause->getDamager();
                        
    $this->kill[$killers->getName] = $this->kill[$killers->getName]+1//Add Kill
                    
    }
                }
            }
    to get kill,
    PHP:
    public function getKill($name){
        return 
    $this->kill[$name];
    }
    //Ex, $this->getKill("korado531m7");
    #return kill
    to get death,
    PHP:
    public function getDeath($name){
        return 
    $this->death[$name];
    }
    //Ex, $this->getDeath("korado531m7");
    #return death
    using global valuable. so it will be deleted kill and death the score when you restarted server or stopped.
    if you want to keep, why don't you use saving to the file (Ex: yml) ?
    Survingo, applqpak and AndrewBit like this.
  3. NycuRO
    Offline

    NycuRO Active Member

    Joined:
    Oct 19, 2015
    Posts:
    64
    Minecraft User:
    NycuRK
    I'm using .yml file,but with suicide server crash....and idk why..
  4. korado531m7
    Offline

    korado531m7 Active Member

    Joined:
    Apr 4, 2015
    Posts:
    158
    Minecraft User:
    korado531m7
    Please send the errors

Share This Page

Advertisement