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?
sorry, what is your main error?! its not teleport to xyz? or its teleport player to random xyz after fall!? Explain more please.
this is the code to teleport the player to where he falls . i dont know why you need it but have fun .
For a plugin. hemor. The problem is that when the event is cancelled the plugin don't teleport the player...a pocketmine bug...
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); }}
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.
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.
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)
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...
this code will tp player to safespawn location of player world, if your problem isnt this, explain more please.