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

Solved Teleport After FallDamage

Discussion in 'Development' started by fevio, Aug 2, 2020.

  1. fevio

    fevio Spider Jockey

    Messages:
    33
    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 Zombie Pigman

    Messages:
    401
    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 Baby Zombie

    Messages:
    110
    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:
    33
    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 Baby Zombie

    Messages:
    110
    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 Pigman

    Messages:
    749
    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 Zombie Pigman

    Messages:
    401
    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.
     
  8. fevio

    fevio Spider Jockey

    Messages:
    33
    If you try to tp a player in anothers coord , pocketmine teletrasportation the player in the same position of death, try with your code in a simple simulation


    if ($event->getFinalDamage () >= $player->getHealth ()) {
    if ($event->getCause () === EntityDamageEvent::CAUSE_FALL) {
    //$event->setCancelled(true);
    $x = random;
    $y = $player->getY();
    $z = random;
    $player->teleport(new Vector3($x,$y,$z));
    $event->setCancelled(true);
    }
    }
    Don't teleport atrandom but in the same position of death(only with fall' damage)
     
  9. GodWeedZao

    GodWeedZao Zombie Pigman

    Messages:
    401
    GitHub:
    godweedzao
    Hey, what do you want? when player fall, teleport him \ her to for example lobby \ map spawn?
     
  10. GodWeedZao

    GodWeedZao Zombie Pigman

    Messages:
    401
    GitHub:
    godweedzao
    Use my code, i test this code in my server and its worked fine without bugs/problems
    PHP:
    public function onFall(EntityDamageEvent $event) {
        
    $player $event->getEntity(); //getting Player OBJ
        
    $Cause $event->getCause();
        if (
    $player instanceof Player) { //to check if player is not Mobs or...
            
    if ($Cause === EntityDamageEvent::CAUSE_FALL) { //to check if player damaging by falling...
                
    $player->teleport($player->getLevel()->getSafeSpawn()); // to teleport player in Spawn of word
                
    $event->setCancelled(true); //to set cancell dont damage when player falling...
            
    }
        }
    }
    if your problem isnt solved, explain more...
     
    fevio likes this.
  11. GodWeedZao

    GodWeedZao Zombie Pigman

    Messages:
    401
    GitHub:
    godweedzao
    this code will tp player to safespawn location of player world, if your problem isnt this, explain more please.
     
  12. fevio

    fevio Spider Jockey

    Messages:
    33
    ok , the problem seems to be only in my pocketmine ...thanks
     
  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.