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

Solved I need help with player move event.

Comments in 'Plugin Development' started by iiDeathStrokeii, Aug 2, 2015.

Thread Status:
Not open for further replies.
  1. iiDeathStrokeii
    Offline

    iiDeathStrokeii Active Member

    Joined:
    Mar 30, 2015
    Posts:
    111
    Minecraft User:
    iiDeathstrokeii
    Why doesnt this work?
    PHP:
    public function portalJoin(PlayerMoveEvent $ev){
                
    $player $ev->getPlayer();
                
    $x round($player->getX());
                
    $y round($player->getY());
                
    $z round($player->getZ());
               
                if(
    $x >= 509.5 and $x <=496.7 and $y >= 27 and $y <=and $z >= 416.5 and $z <=416.7){
                    
    $player->sendMessage("Teleporting...");
                }
  2. Xirano
    Offline

    Xirano New Member

    Joined:
    Aug 2, 2015
    Posts:
    17
    Minecraft User:
    xirano78
    Do you have add this ? use pocketmine\event\entity\EntityMoveEvent
  3. Calrizer
    Offline

    Calrizer Active Member

    Joined:
    Jan 17, 2015
    Posts:
    102
    Minecraft User:
    callumdrain
    First you should save the players coordinates using:
    PHP:
    $x $player->getFloorX();
    $y $player->getFloorY();
    $z $player->getFloorZ();
    Then try to use whole numbers in your detection on if the player is whiten the portal. And use && instead of 'and'.
    Xirano likes this.
  4. iiDeathStrokeii
    Offline

    iiDeathStrokeii Active Member

    Joined:
    Mar 30, 2015
    Posts:
    111
    Minecraft User:
    iiDeathstrokeii
    I use:
    PHP:
    use pocketmine\event\player\PlayerMoveEvent;
  5. Xirano
    Offline

    Xirano New Member

    Joined:
    Aug 2, 2015
    Posts:
    17
    Minecraft User:
    xirano78
    Add it and i think its work EntityMoveEvent :)
    use pocketmine\event\entity\EntityMoveEvent
  6. iiDeathStrokeii
    Offline

    iiDeathStrokeii Active Member

    Joined:
    Mar 30, 2015
    Posts:
    111
    Minecraft User:
    iiDeathstrokeii
    uhhm i tried this:
    PHP:
     public function portalJoin(PlayerMoveEvent $ev){
                
    $player $ev->getPlayer();
                
    $x round($player->getX());
                
    $y round($player->getY());
                
    $z round($player->getZ());
               
                if(
    $x >= 509.5 and $x <=496.7 and $y >= 27 and $y <=and $z >= 416.5 and $z <=416.7){
                    
    $player->sendMessage("Teleporting...");
                }
    still not working though.
  7. iiDeathStrokeii
    Offline

    iiDeathStrokeii Active Member

    Joined:
    Mar 30, 2015
    Posts:
    111
    Minecraft User:
    iiDeathstrokeii
    I think that would work but when you say entity its probably for thing such as mobs although they are not fully implemented and PlayerMoveEvent does work.
  8. Calrizer
    Offline

    Calrizer Active Member

    Joined:
    Jan 17, 2015
    Posts:
    102
    Minecraft User:
    callumdrain
    Player move event will work just fine. :)
    And if you are aiming to teleport a player to desired location or world use these:
    PHP:
    //Sends To Position Within Current World
    $newPos = new Vector3($x$y$z);
    $player->teleport($newPos);
    //Sends To New World
    $player->teleport($this->getServer()->getLevelByName($world)->getSafeSpawn());
  9. iiDeathStrokeii
    Offline

    iiDeathStrokeii Active Member

    Joined:
    Mar 30, 2015
    Posts:
    111
    Minecraft User:
    iiDeathstrokeii
  10. iiDeathStrokeii
    Offline

    iiDeathStrokeii Active Member

    Joined:
    Mar 30, 2015
    Posts:
    111
    Minecraft User:
    iiDeathstrokeii
    Thanks for extra code but the current code still doesnt work.
    help would be appreciated.
  11. Calrizer
    Offline

    Calrizer Active Member

    Joined:
    Jan 17, 2015
    Posts:
    102
    Minecraft User:
    callumdrain
    As I said here:
    Have you tried using whole numbers and $player->getFloorX?
  12. iiDeathStrokeii
    Offline

    iiDeathStrokeii Active Member

    Joined:
    Mar 30, 2015
    Posts:
    111
    Minecraft User:
    iiDeathstrokeii
    yes but didnt work:
    PHP:
    public function portalJoin(PlayerMoveEvent $ev){
                
    $player $ev->getPlayer();
                
    $x round($player->getX());
                
    $y round($player->getY());
                
    $z round($player->getZ());
              
                if(
    $x >= 509.5 and $x <=496.7 and $y >= 27 and $y <=and $z >= 416.5 and $z <=416.7){
                    
    $player->sendMessage("Teleporting...");
                }
  13. Calrizer
    Offline

    Calrizer Active Member

    Joined:
    Jan 17, 2015
    Posts:
    102
    Minecraft User:
    callumdrain
    You're sill using:
    PHP:
    $x round($player->getX();
    When you should use:
    PHP:
    $x $player->getFloorX();
    And you're still using non integer numbers like: 509.4. Make them whole.
    iksaku likes this.
  14. iiDeathStrokeii
    Offline

    iiDeathStrokeii Active Member

    Joined:
    Mar 30, 2015
    Posts:
    111
    Minecraft User:
    iiDeathstrokeii
    lol sorry that was th eold copy and paste lol
    PHP:
    public function portalJoin(PlayerMoveEvent $ev){
                
    $player $ev->getPlayer();
                
    $x $player->getFloorX();
                
    $y $player->getFloorY();
                
    $z $player->getFloorZ();
               
                if(
    $x >= 509 &&  $x <=497 &&  $y >= 27 &&  $y <=&&  $z >= 417 &&  $z <=417){
                    
    $player->sendMessage("Teleporting...");
                }
    it didnt work :(
  15. iiDeathStrokeii
    Offline

    iiDeathStrokeii Active Member

    Joined:
    Mar 30, 2015
    Posts:
    111
    Minecraft User:
    iiDeathstrokeii
  16. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    You dont need to round(); just do:
    PHP:
    $x $player->getFloorX();
    $y $player->getFloorY();
    $z $player->getFloorZ();
    and if you wanna be sure that it's listening to player move event add some output message
    PHP:
    public function onMove(PlayerMoveEvent $event){
    $player $event;
    // Blah blah blah
    echo $player->getName().' Moved';
    }
    I had same problem with position checking :D
    PHP:
    ($test->getX() >= $a->getX() && $test->getX() <= $b->getX() && $test->getY() >= $a->getY() && $test->getY() <= $b->getY() && $test->getZ() >= $a->getZ() && $test->getZ() <= $b->getZ());
    Maby this helps
    I'm 70% sure that it will send you more then one message
    Last edited: Aug 2, 2015
  17. Exxarion
    Offline

    Exxarion Active Member Plugin Developer

    Joined:
    Jan 5, 2014
    Posts:
    242
    Plugins:
    1
    Minecraft User:
    Notch
    PHP:
    use pocketmine\event\entity\EntityMoveEvent;

    public function 
    portalJoin(EntityMoveEvent $ev){
                
    $player $ev->getPlayer();
                
    $x $player->getFloorX();
                
    $y $player->getFloorY();
                
    $z $player->getFloorZ();
              
                if(
    $x >= 509 &&  $x <=497 &&  $y >= 27 &&  $y <=&&  $z >= 417 &&  $z <=417){
                    
    $player->sendMessage("YOU JUST MOVED!");
                } 
    Try that
    iksaku and iiDeathStrokeii like this.
  18. iiDeathStrokeii
    Offline

    iiDeathStrokeii Active Member

    Joined:
    Mar 30, 2015
    Posts:
    111
    Minecraft User:
    iiDeathstrokeii
    Yes
  19. Gamecrafter
    Offline

    Gamecrafter

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
    Why use "&&" instead of "and"? They both server the same purpose. :p
  20. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    True, but i always use '&&' it's neater
    Legoboy0215 likes this.
Thread Status:
Not open for further replies.

Share This Page

Advertisement