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

Solved Cancel player death and set health

Comments in 'Plugin Development' started by thebigsmileXD, Sep 20, 2015.

  1. thebigsmileXD
    Offline

    thebigsmileXD Banned

    Joined:
    May 19, 2015
    Posts:
    845
    Plugins:
    1
    Minecraft User:
    XenialDan
    How can i set the health of the player back to maximum when a player dies and cancel the death of the player?

    The console tells me PlayerDeathEvent is not cancellable;
  2. Hotshot_9930
    Offline

    Hotshot_9930 Notable Member Plugin Developer

    Joined:
    May 26, 2014
    Posts:
    665
    Plugins:
    2
    Minecraft User:
    HotshotHD
    Use the EntityDamagedByEntity event.
    Check if the entity is a player, and if their health is at 1, set it back to 10.
  3. thebigsmileXD
    Offline

    thebigsmileXD Banned

    Joined:
    May 19, 2015
    Posts:
    845
    Plugins:
    1
    Minecraft User:
    XenialDan
    But a player could die because of fall damage or void, then what?
  4. Hotshot_9930
    Offline

    Hotshot_9930 Notable Member Plugin Developer

    Joined:
    May 26, 2014
    Posts:
    665
    Plugins:
    2
    Minecraft User:
    HotshotHD
    Check if the cause of damage is from a block and set the health back to full. Idk if it will work since fall damage could immediately set health to 0, but its worth a try
  5. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    check DAmageEvent if $damage >= $player->getHealth()
  6. AndrewBit
    Offline

    AndrewBit Notable Member

    Joined:
    Jun 18, 2015
    Posts:
    435
    Minecraft User:
    AndrewBit4
    OK, I'm not pro at PocketMine API, but I think this is enought:
    PHP:
    public function OnKill(PlayerDeathEvent $event){
    $cause $event->getEntity()->getLastDamageCause();if($cause instanceof EntityDamageByEntityEvent){
    $killer $cause->getDamager();
    if(
    $killer instanceof Player and $killer->getHealt() == 1){
    $killer->setHealth($killer->getHealth() + 
    #I'm not sure if + 8 is the max default health or no
    );
    }
    }
    }
    *If I have any error, please, tell me!
  7. Hotshot_9930
    Offline

    Hotshot_9930 Notable Member Plugin Developer

    Joined:
    May 26, 2014
    Posts:
    665
    Plugins:
    2
    Minecraft User:
    HotshotHD
    He/she doesnt want to set the killer's health back to full.
    They want to prevent death completely.
  8. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    PHP:
    public function onHit(EntityDamageEvent $e){
        if(
    $e->getEntity() instanceof Player && $e->getFinalDamage() >= $e->getEntity()->getHealth()){
            
    //something to cancel or death
        
    }
    }
    PEMapModder likes this.
  9. thebigsmileXD
    Offline

    thebigsmileXD Banned

    Joined:
    May 19, 2015
    Posts:
    845
    Plugins:
    1
    Minecraft User:
    XenialDan
    *getHealth ^^
    You cant cancel it, thats the problem.
  10. Gamecrafter
    Offline

    Gamecrafter

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
    You can't cancel it, but you can use code hacks. What exactly do you want to do?
  11. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    maybe he want to make autorespawn
  12. thebigsmileXD
    Offline

    thebigsmileXD Banned

    Joined:
    May 19, 2015
    Posts:
    845
    Plugins:
    1
    Minecraft User:
    XenialDan
    Something like instant respawning. No "respawn / back to title" title.
    But only if $this->isPlaying($player)==true
  13. thebigsmileXD
    Offline

    thebigsmileXD Banned

    Joined:
    May 19, 2015
    Posts:
    845
    Plugins:
    1
    Minecraft User:
    XenialDan
    Your timing is weird. just was writing.
  14. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    there is not function for that here. So you must make it manually
  15. Gamecrafter
    Offline

    Gamecrafter

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
    He already knows that, you don't have to tell him again. :p
    thebigsmileXD likes this.
  16. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    so what he want? i think heal player, remove inventory and teleport to spawn is easy for him
  17. thebigsmileXD
    Offline

    thebigsmileXD Banned

    Joined:
    May 19, 2015
    Posts:
    845
    Plugins:
    1
    Minecraft User:
    XenialDan
    Thanks, finally someone understands me ;)
    @Creeperface you always post comments with no content. Thats ineffective.

    Also setting health and clearing inventory, then teleporting does not work well.
    The player is still "killed", but at the new position and the screen does not show up. The items are laying there at the ground.
  18. Gamecrafter
    Offline

    Gamecrafter

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
    Well that explains why @Creeperface has 1,011 posts and only 157 likes. :p (these numbers are correct at the time this post was made)
    thebigsmileXD likes this.
  19. Frog
    Offline

    Frog New Member

    Joined:
    Sep 6, 2015
    Posts:
    6
    Minecraft User:
    FROG52
    The plugin NoVoid makes to where players don't die when they enter the void so try that, and is OITC almost ready?
  20. jojoe77777
    Offline

    jojoe77777 Notable Member Plugin Developer

    Joined:
    May 28, 2015
    Posts:
    653
    Plugins:
    1
    Minecraft User:
    jojoe77777
    EntityDamageEvent IS cancellable, but not PlayerDeathEvent.

Share This Page

Advertisement