Hi, I'm trying to make a plugin which shoots the player from anywhere through the air to a specific position (for example 107, 71, 17). I don't want to teleport the player, more like a jump boost that the player is flying. How can I do that?
setMotion() And the server will kick the player because of Flying not enabled. https://github.com/PocketMine/PocketMine-MP/blob/master/src/pocketmine/Player.php#L1449
I've already tried setMotion, but the problem is that you can't set coordinates in setMotion. I don't know how to calculate it correctly that the player exactly lands on the specific position. Same problem with ->knockBack(), it would be really difficult to set it on the right values that the player lands on the correct position. How to do that?
Check EssentialsPE's /jump Code: <?php namespace EssentialsPE\Commands; use EssentialsPE\BaseFiles\BaseAPI; use EssentialsPE\BaseFiles\BaseCommand; use pocketmine\command\CommandSender; use pocketmine\Player; use pocketmine\utils\TextFormat; class Jump extends BaseCommand{ /** * @param BaseAPI $api */ public function __construct(BaseAPI $api){ parent::__construct($api, "jump", "Teleport you to the block you're looking at", null, false, ["j", "jumpto"]); $this->setPermission("essentials.jump"); } /** * @param CommandSender $sender * @param string $alias * @param array $args * @return bool */ public function execute(CommandSender $sender, $alias, array $args){ if(!$this->testPermission($sender)){ return false; } if(!$sender instanceof Player || count($args) !== 0){ $this->sendUsage($sender, $alias); return false; } $block = $sender->getTargetBlock(100, BaseAPI::NON_SOLID_BLOCKS); if($block === null){ $sender->sendMessage(TextFormat::RED . "There isn't a reachable block"); return false; } if(!$sender->getLevel()->getBlock($block->add(0, 2))->isSolid()){ $sender->teleport($block->add(0, 1)); return true; } switch($side = $sender->getDirection()){ case 0: case 1: $side += 3; break; case 3: $side += 2; break; default: break; } if(!$block->getSide($side)->isSolid()){ $sender->teleport($block); } return true; } }
I think thats only a extended teleport function, but not a jump function like I mean. I mean something like Knockback Jump Pads through the air, but not teleport.
I researched a bit and got it working, you have to calculate the coordinate change when a player has an x and y velocity of 1, I pasted the result in a file and used it to calculate with it, here is the code, it works well: PHP: $pl = $event->getPlayer();// + 6.5235748291016 x$wishX = 87;$wishZ = 49;$x = ($wishX - $pl->x) / 6.5235748291016;$z = ($wishZ - $pl->z) / 6.5235748291016;$pl->setMotion(new Vector3($x, 1, $z)); $wishX and $wishZ are the coordinates the player should get teleported to.
One more question: In the lobby, players are in survival game mode. So they are always kicked for flying. When I do: $pl->setAllowFlight(true); $pl->setMotion(new Vector3($x, 1, $z)); $pl->setAllowFlight(false); It does not work, because it calls setAllowFlight(false); directly after setMotion(); is called and not after the movement is finished. How can I solve that?