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

position PlayerMoveEvent

Comments in 'Plugin Development' started by Khaled_Craft1b, Sep 5, 2016.

  1. Khaled_Craft1b
    Offline

    Khaled_Craft1b New Member

    Joined:
    Jul 27, 2015
    Posts:
    8
    Minecraft User:
    Khaled_Craft1b
    I know how but there does not appear an error
    If there is a mis- classed me.
    PHP:
    public function onMove(PlayerMoveEvent $event){
          
    $player $event->getPlayer();
          
    $x1 $this->plugin->getConfig()->get("x1");
          
    $z1 $this->plugin->getConfig()->get("z1");
          
    $y1 $this->plugin->getConfig()->get("y1");
          
    $x2 $this->plugin->getConfig()->get("x2");
          
    $y2 $this->plugin->getConfig()->get("y2");
          
    $z2 $this->plugin->getConfig()->get("z2");
          for(
    $x $x1$x $x2$x++){
              for(
    $y $y1$y $y2$y++){
                  for(
    $z $z1$z $z2$z++){
                       if(
    $event->getFrom()->getFloorX() === $x){
                            if(
    $event->getFrom()->getFloorY() === $y){
                                 if(
    $event->getFrom()->getFloorZ() === $z){
                                     
    $player->sendMessage("position ok");
                                 }
                            }
                       }
                  }
              }
          }
      }
  2. wolfdale
    Offline

    wolfdale Active Member Plugin Developer

    Joined:
    Dec 3, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    ace
    If you are trying to find out if player is in an area use
    PHP:
    //                      Player pos     Pos 1          Pos 2
    public function isInside(Vector3 $ppVector3 $p1Vector3 $p2){
         return ((
    min($p1->getX(),$p2->getX()) <= $pp->getX()) &&
             (
    max($p1->getX(),$p2->getX()) >= $pp->getX()) &&
             (
    min($p1->getY(),$p2->getY()) <= $pp->getY()) &&
             (
    max($p1->getY(),$p2->getY()) >= $pp->getY()) &&
             (
    min($p1->getZ(),$p2->getZ()) <= $pp->getZ()) &&
             (
    max($p1->getZ(),$p2->getZ()) >= $pp->getZ()));
       }
  3. Khaled_Craft1b
    Offline

    Khaled_Craft1b New Member

    Joined:
    Jul 27, 2015
    Posts:
    8
    Minecraft User:
    Khaled_Craft1b
    Can you explain more please
  4. wolfdale
    Offline

    wolfdale Active Member Plugin Developer

    Joined:
    Dec 3, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    ace
    That function will return whether the player position is inside the area marked by the 2 positions
    In your case, this is the code you need
    PHP:
    public function isInside(Vector3 $ppVector3 $p1Vector3 $p2){
    return ((
    min($p1->getX(),$p2->getX()) <= $pp->getX()) &&
    (
    max($p1->getX(),$p2->getX()) >= $pp->getX()) &&
    (
    min($p1->getY(),$p2->getY()) <= $pp->getY()) &&
    (
    max($p1->getY(),$p2->getY()) >= $pp->getY()) &&
    (
    min($p1->getZ(),$p2->getZ()) <= $pp->getZ()) &&
    (
    max($p1->getZ(),$p2->getZ()) >= $pp->getZ()));
    }

    public function 
    onMove(PlayerMoveEvent $event){
    $player $event->getPlayer();
    $x1 $this->plugin->getConfig()->get("x1");
    $z1 $this->plugin->getConfig()->get("z1");
    $y1 $this->plugin->getConfig()->get("y1");
    $x2 $this->plugin->getConfig()->get("x2");
    $y2 $this->plugin->getConfig()->get("y2");
    $z2 $this->plugin->getConfig()->get("z2");
    if(
    $this->isInside($player,new Vector3($x1,$y1,$z1),new Vector3($x2,$y2,$z2))) $player->sendMessage("position ok");
    }
    Thunder33345 likes this.
  5. Khaled_Craft1b
    Offline

    Khaled_Craft1b New Member

    Joined:
    Jul 27, 2015
    Posts:
    8
    Minecraft User:
    Khaled_Craft1b
    Thanks I'm search for this pleased me a week ago Thank you :)

Share This Page

Advertisement