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

Get the victim in a pvp fight?

Comments in 'Plugin Development' started by dxm_hippie, Apr 17, 2015.

  1. dxm_hippie
    Offline

    dxm_hippie Active Member Plugin Developer

    Joined:
    Feb 1, 2015
    Posts:
    413
    Plugins:
    1
    Minecraft User:
    XxDXM_hippiexX
    Im actually trying to get the player who killed as well as the player who dies..not sure how to get the victim

    PHP:
    public function onPlayerDeath(PlayerDeathEvent $event){
                
    $player $event->getEntity();
                
    $cause $event->getEntity()->getLastDamageCause()->getCause();
                
    $entity $event->getEntity();
                
    $cause $entity->getLastDamageCause();
                if(
    $cause instanceof EntityDamageByEntityEvent) {
                
    $killer $cause->getDamager()->getPlayer()
                
    $victim $player->getEntity........... :(
  2. LDX
    Offline

    LDX Notable Member Plugin Developer

    Joined:
    Oct 2, 2013
    Posts:
    1,429
    Plugins:
    14
    PHP:
    $victim $event->getPlayer();
    Also, when you call $cause->getDamager(), you don't need to call Player::getPlayer() because it already returns at entity. You do, however, have to make sure the entity is a player.
    dxm_hippie likes this.
  3. Sulfatezzz
    Offline

    Sulfatezzz New Member

    Joined:
    Apr 5, 2015
    Posts:
    6
    Minecraft User:
    Sulfatezzz
    Here an example how you can handle player deaths

    PHP:
    public function onPlayerDeath(PlayerDeathEvent $event)
    {
        
    $entity $event->getEntity();
        
    $killer $entity->getLastDamageCause();
        if(
    $killer instanceof EntityDamageByEntityEvent)
        {
            
    $killer $killer->getDamager();
            if(
    $killer instanceof Player)
            {
                
    //The reason for the death on our Player was an other Player ($killer)
            
    }
            else
            {
                
    //The reason for the death on our Player ($entity) was NOT an Player but it was an Entity
            
    }
        }
        else
        {
            
    //The reason for the death on our Player ($entity) was NOT an Player/Entity
        
    }
    }
  4. dxm_hippie
    Offline

    dxm_hippie Active Member Plugin Developer

    Joined:
    Feb 1, 2015
    Posts:
    413
    Plugins:
    1
    Minecraft User:
    XxDXM_hippiexX
    ok, doesn't the "//The reason for the death on our Player ($entity) was NOT an Player/Entity" not do anything? i always thought the // was just to add notes or somthing.
  5. Sulfatezzz
    Offline

    Sulfatezzz New Member

    Joined:
    Apr 5, 2015
    Posts:
    6
    Minecraft User:
    Sulfatezzz
    Yes, that are comments/notes to make it "more" understandable for you.
    dxm_hippie likes this.
  6. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Yes, and isn't he adding notes now?
  7. dxm_hippie
    Offline

    dxm_hippie Active Member Plugin Developer

    Joined:
    Feb 1, 2015
    Posts:
    413
    Plugins:
    1
    Minecraft User:
    XxDXM_hippiexX
    I was just making sure lol i didnt think they did anything..but wonted to be sure.
  8. dxm_hippie
    Offline

    dxm_hippie Active Member Plugin Developer

    Joined:
    Feb 1, 2015
    Posts:
    413
    Plugins:
    1
    Minecraft User:
    XxDXM_hippiexX
    Instead of making a new thread..ill just ask here lol i got what i was doing with the killer and victim working fine now im wondering if i can use things from economy api in a different plugin? What i am working on is taking killcash or killmoney and modding it a bit..dont hate me im not planning on taking credit or trying to post it, i like the plugin but im making it take the money from the victim now i just need to figure out how to cancel the event if the victim has no money..
    PHP:
    public function onPlayerDeath(PlayerDeathEvent $event){
            if(
    $this->economy == true && $this->config->get("enable") == "true"){
                   
                       
                       
    $entity $event->getEntity();
                       
    $killer $entity->getLastDamageCause();
                    if(
    $killer instanceof EntityDamageByEntityEvent){
                       
                    }
                       
    $killer $killer->getDamager();
                    if(
    $killer instanceof Player)
                    if(
    $this->config->get("economy-plugin") == "EconomyAPI") {
                        
    $msg str_replace("{money}"$this->config->get("money"), $this->config->get("message"));
                        
    $killer->sendMessage("$msg");
                                            
    $entity->sendMessage("$Vmessage");
                                            
    $this->getServer()->getPluginManager()->getPlugin("EconomyAPI")->reduceMoney($entity->getName(), $this->config->get("money"));
                        
    $event->$this->getServer()->getPluginManager()->getPlugin("EconomyAPI")->addMoney($killer->getName(), $this->config->get("money"));
                        return 
    true;
                                    }
                                            
    $money $this->config->get("money");
                    if(
    EconomyAPI::getInstance()->reduceMoney($entity$moneytrue"EconomyATP") === EconomyAPI::RET_INVALID){
                        
    $killer->sendMessage("Victim had no money to steal!"));
                        return 
    true;
    LDX likes this.
  9. dxm_hippie
    Offline

    dxm_hippie Active Member Plugin Developer

    Joined:
    Feb 1, 2015
    Posts:
    413
    Plugins:
    1
    Minecraft User:
    XxDXM_hippiexX
    maybe somthing like this?
    PHP:
    if($this->getServer()->getPluginManager()->getPlugin("EconomyAPI")->getMoney($entity) === EconomyAPI::RET_INVALID)

Share This Page

Advertisement