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

Solved Keep inventory when you fell out in the void.

Discussion in 'Development' started by KHAV, Sep 15, 2017.

  1. KHAV

    KHAV Baby Zombie

    Messages:
    152
    GitHub:
    xkhhv
    Hello!
    i tried to make keep inventory when the player dies it works in all cases except [VOID DEATH] so when the player fall out in the void his inventory become empty.

    I tried:
    PHP:
    public function onDeath(PlayerDeathEvent $event){
    $player $event->getEntity();
    if(
    $player instanceof EntityDamageEvent){
    if(
    $player->getCause() == EntityDamageEvent::CAUSE_VOID){
    $event->setKeepInventory(true);
    }
    }
    }
    But it is not work.
    So how i can fix it?
     
  2. Az928

    Az928 Baby Zombie

    Messages:
    140
    GitHub:
    theaz928
    All of your methods are wrong,
    PHP:
    public function ondeath(PlayerDeathEvent $event){
      
    $player $event->getPlayer();
      if(
    $player->getLastDamageCause()->getCause() == EntityDamageEvent::CAUSE_VOID){
       
    $event->setKeepInventory(true);
      }
    }
    FAQ:
    $player->getLastDamageCause() returns an instance of EntityDamageEvent, so you can do $player->getLastDamageCause()->getCause()

    You can use both $player = $event->getEntity() or $player = $event->getPlayer(); as both returns same thing
     
    Muqsit, jasonwynn10 and Karanpatel567 like this.
  3. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    Did either of you notice that the event causes the inventory only to be kept when the player dies in the void rather than "when the player fall out in the void his inventory become empty"
     
    Sandertv, Az928 and EdwardHamHam like this.
  4. Levi

    Levi Skeleton

    Messages:
    955
    GitHub:
    captainleviftw
    Why not just teleport the player to spawn when they reach -1?
     
  5. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    Workarounds are not solutions
     
  6. Levi

    Levi Skeleton

    Messages:
    955
    GitHub:
    captainleviftw
    does that mean i can't suggest?
     
  7. KHAV

    KHAV Baby Zombie

    Messages:
    152
    GitHub:
    xkhhv
    I tried this but i have a new proplem when i death my items back but when i tap on respawn button my inventory become empty!
     
  8. KHAV

    KHAV Baby Zombie

    Messages:
    152
    GitHub:
    xkhhv
    Ok i fix it xD thx for all!
     
    Az928 likes this.
  9. sharletsings123

    sharletsings123 Baby Zombie

    Messages:
    116
    GitHub:
    sharletk
    Awesome!
    I was gonna say you can tag it as Solved anyways its done.
     
  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.