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

Kill but don't kill player.

Discussion in 'Development' started by RumDaDuMCPE, Aug 23, 2018.

  1. RumDaDuMCPE

    RumDaDuMCPE Witch

    Messages:
    67
    GitHub:
    RumDaDuMCPE
    Is there a way to prevent the PlayerDeathEvent from being called so that the 'You Died' thingy doesn't come up and I can replace it with my custom code?
    Example:
    PHP:
    /**
    * @param EntityDamageEvent $damageEvent
    */
    public function catchDamage(EntityDamageEvent $damageEvent)
    {
        
    $entity $damageEvent->getEntity();
        if (
    $entity instanceof Player && $damageEvent instanceof EntityDamageByEntityEvent) {
            
    $player $entity;
            if ((
    $player->getHealth() - $damageEvent->getFinalDamage()) < 1) { // BOIIII
                
    $this->kill($player);
            }
        }
    }

    /**
    * @param Player $player
    */
    private function kill(Player $player)
    {
        
    $player->getInventory()->clearAll();
        
    $player->setHealth($player->getMaxHealth());
        
    $player->setFood($player->getMaxFood());
        if (
    $player->hasEffects()) {
            
    $player->removeAllEffects();
        }
        
    $player->addTitle("u died lol""watanub kys"2020 320);
    }
     
  2. Eduardo

    Eduardo Baby Zombie

    Messages:
    100
    GitHub:
    xBeastMode
    Try cancelling the event before calling "$this->kill()".
     
    corytortoise, Kyd and RumDaDuMCPE like this.
  3. MalakasPlayzMCPE

    MalakasPlayzMCPE Zombie Pigman

    Messages:
    667
    After $this->kill($player); add $damageEvent->setCancelled();

    Edit: Lagggggg
     
    RumDaDuMCPE likes this.
  4. RumDaDuMCPE

    RumDaDuMCPE Witch

    Messages:
    67
    GitHub:
    RumDaDuMCPE
    Thanks, I'll try that.
     
  5. RumDaDuMCPE

    RumDaDuMCPE Witch

    Messages:
    67
    GitHub:
    RumDaDuMCPE
    Noooooooooooooooooo
    how i fix dis
     
  6. Kyd

    Kyd Zombie Pigman

    Messages:
    678
    GitHub:
    boi1216
    Listen for PlayerDeathEvent and set health to 20
     
  7. RumDaDuMCPE

    RumDaDuMCPE Witch

    Messages:
    67
    GitHub:
    RumDaDuMCPE
    Before I set the health to max, The player's probably ded lol
     
  8. RumDaDuMCPE

    RumDaDuMCPE Witch

    Messages:
    67
    GitHub:
    RumDaDuMCPE
    The event calls that Respawn screen. I hate that. "You died!". Meh .-.
     
    OnTheVerge likes this.
  9. MalakasPlayzMCPE

    MalakasPlayzMCPE Zombie Pigman

    Messages:
    667
    PHP:
    public function catchDamage(EntityDamageEvent $damageEvent)
    {
        
    $entity $damageEvent->getEntity();
        if (
    $entity instanceof Player && $damageEvent instanceof EntityDamageByEntityEvent) {
            
    $player $entity;
            if ((
    $player->getHealth() - $damageEvent->getFinalDamage()) < 1) { // BOIIII
                
    $damageEvent->setCancelled();
                
    $this->kill($player);
            }
        }
    }
     
  10. RumDaDuMCPE

    RumDaDuMCPE Witch

    Messages:
    67
    GitHub:
    RumDaDuMCPE
    Lol. I asked you how to fix the lag.
     
  11. MalakasPlayzMCPE

    MalakasPlayzMCPE Zombie Pigman

    Messages:
    667
    I mean, my internet lags. The method is okay. This happened to me twice yesterday. Posting something when someone else already replied.
     
    OnTheVerge and RumDaDuMCPE like 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.