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

Solved How to jump a player to a specific position

Comments in 'Plugin Development' started by jjmc, Apr 16, 2016.

  1. jjmc
    Offline

    jjmc New Member

    Joined:
    Oct 18, 2015
    Posts:
    41
    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?
  2. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
  3. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
  4. jjmc
    Offline

    jjmc New Member

    Joined:
    Oct 18, 2015
    Posts:
    41
    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?
  5. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
    Some random math, will ask @Aodzip
  6. Muqsit
    Offline

    Muqsit Active Member

    Joined:
    Sep 9, 2015
    Posts:
    175
    Minecraft User:
    Muqsit
    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;
        }
    }
  7. jjmc
    Offline

    jjmc New Member

    Joined:
    Oct 18, 2015
    Posts:
    41
    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.
  8. MyNameIsTriXz
    Offline

    MyNameIsTriXz Notable Member

    Joined:
    Aug 17, 2015
    Posts:
    538
    Minecraft User:
    MyNameIsTriXz
    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($x1$z));


    $wishX and $wishZ are the coordinates the player should get teleported to.
    Last edited: Apr 16, 2016
    jjmc likes this.
  9. jjmc
    Offline

    jjmc New Member

    Joined:
    Oct 18, 2015
    Posts:
    41
    Thank you, it works great!
  10. jjmc
    Offline

    jjmc New Member

    Joined:
    Oct 18, 2015
    Posts:
    41
    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?
  11. jjmc
    Offline

    jjmc New Member

    Joined:
    Oct 18, 2015
    Posts:
    41
    Solved it with setting setAllowFlight(false); on EntityDamageEvent on fall damage.
  12. MyNameIsTriXz
    Offline

    MyNameIsTriXz Notable Member

    Joined:
    Aug 17, 2015
    Posts:
    538
    Minecraft User:
    MyNameIsTriXz
    Yeah, or generally turn it off in the config.

Share This Page

Advertisement