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

Sign knockback

Discussion in 'Development' started by #A6543, Jan 25, 2017.

  1. #A6543

    #A6543 Zombie

    Messages:
    267
    How can I check if a player is near a sign with "knockback" on the first line an give the player knockback?
     
  2. Jack Noordhuis

    Jack Noordhuis Zombie Pigman Poggit Reviewer

    Messages:
    618
    GitHub:
    JackNoordhuis
    Incorrect. You can call the Living::knockback() function to knock back a living entity.
     
    Muqsit and InspectorGadget like this.
  3. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    PHP:
    const RADIUS_SQ 16;
    /** @var Player $player */
    foreach($player->getLevel()->getTiles() as $tile){
        if(
    $tile instanceof Sign){
            if(
    $player->distanceSquared($tile) <= self::RADIUS_SQ){
                
    $player->setMotion($tile->add($player)->normalize()->multiply(4));
            }
        }
    }
     
  4. #A6543

    #A6543 Zombie

    Messages:
    267
    This isn't working. Nothing happens and no errors
    PHP:
    public function onPlayerMove(PlayerMoveEvent $event) {

    $player $event->getPlayer();


    //const RADIUS_SQ = 16;
    foreach($player->getLevel()->getTiles() as $tile){
        if(
    $tile instanceof Sign){
            if(
    $player->distanceSquared($tile) <= 3){
            
    $player->sendMessage("Test");
                
    $player->setMotion($tile->add($player)->normalize()->multiply(4));
            }
        }
    }
    }
     
  5. EdwardHamHam

    EdwardHamHam Skeleton

    Messages:
    962
    GitHub:
    edwardhamham
    Oh huh. I didn't know that.
     
  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.