Teleport After FallDamage

Discussion in 'Development' started by fevio, Aug 2, 2020 at 12:58 PM.

  1. fevio

    fevio Spider Jockey

    Messages:
    27
    I had should to teleport player when he falls and died , i have tried this code in EntityDamageEvent:
    if ($event->getFinalDamage () >= $player->getHealth ()) {
    if ($event->getCause () === EntityDamageEvent::CAUSE_FALL) {
    $event->setCancelled(true);
    $player->teleport(new Vector3(0,0,0));
    }
    }

    The problem is that teleport to the same position as death.
    Someone have any ideas to solve?
     
  2. GodWeedZao

    GodWeedZao Baby Zombie

    Messages:
    144
    GitHub:
    godweedzao
    sorry, what is your main error?! its not teleport to xyz? or its teleport player to random xyz after fall!? Explain more please.
     
  3. hexmor

    hexmor Slime

    Messages:
    98
    GitHub:
    h3xmor
    this is the code to teleport the player to where he falls . i dont know why you need it but have fun .
     
  4. fevio

    fevio Spider Jockey

    Messages:
    27
    For a plugin. hemor.

    The problem is that when the event is cancelled the plugin don't teleport the player...a pocketmine bug...
     
  5. hexmor

    hexmor Slime

    Messages:
    98
    GitHub:
    h3xmor
    well then cancel after teleportation . like this

    PHP:
    if ($event->getFinalDamage () >= $player->getHealth ()) {
        if (
    $event->getCause () === EntityDamageEvent::CAUSE_FALL) {
                           
    //$event->setCancelled(true);
    $x $player->getX();
    $y $player->getY();
    $z $player->getZ();
                           
    $player->teleport(new Vector3($x,$y,$z));
    $event->setCancelled(true);
        }
    }
     
  6. Primus

    Primus Zombie

    Messages:
    389
    Is that so? Doesn't make sense. The code should run independent of the event. Could you prove the point by showing the problematic pocketmine source code or the issue in Github? Also, the $force = true, actually does nothing.
     
  7. GodWeedZao

    GodWeedZao Baby Zombie

    Messages:
    144
    GitHub:
    godweedzao
    Oh,XD now i underestand why it has error, because you used this code onEntityDamage, and you set to cancell damage if player fall he doesnt damage, so you code when running player damaging by cause fall.
    you should delete that $event->setCancelled(true); like hexmor's Code.

    also, problem Solved, change prefix to SOLVED.
     

Share This Page

  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.