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

CHAOS DIRECTIONS need Help!

Comments in 'Plugin Development' started by Misaka05323, Apr 14, 2015.

  1. Misaka05323
    Offline

    Misaka05323 New Member

    Joined:
    Dec 17, 2014
    Posts:
    5
    Minecraft User:
    Misaka05323
    First of all,my English is poor,may I can express my question correctly.
    I want to develope a plugin that can:
    When player press right button,he move left.
    When player press left button,he move right.
    When player press up button,he move back.

    Can Pocketmine make this idea come true?
    Which function should I use?

    Thank you very much!
  2. aliuly
    Offline

    aliuly Notable Member Plugin Developer

    Joined:
    Feb 8, 2014
    Posts:
    1,086
    Plugins:
    17
    You need to capture the onPlayerMove event and in there do:

    PHP:
    $to $event->getTo();
    $from $event->getFrom();
    $dx $to->getX() - $from->getX();
    $dy $to->getY() - $from->getY();
    $dz $to->getZ() - $from->getZ();
    $to->setComponents($from->getX() - $dx$to->getY(), $from-getZ() - $dz);

    // You should check collisions here!

    $event->setTo($to);
    EvolSoft and Falk like this.
  3. Misaka05323
    Offline

    Misaka05323 New Member

    Joined:
    Dec 17, 2014
    Posts:
    5
    Minecraft User:
    Misaka05323
    Thank you for your reply,but it didn't work.

    PHP:
    <?php



    namespace mine\ChaosDirection;

    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\Server;
    use 
    pocketmine\event\player\PlayerMoveEvent;
    use 
    pocketmine\math\Vector3;
    use 
    pocketmine\Player;

    class 
    main extends PluginBase implements Listener {

        public function 
    onEnable(){
           
    $this->getServer()->getPluginManager()->registerEvents($this,$this);  
        }

        public function 
    onPlayerMove(PlayerMoveEvent $event){
            echo 
    '1';
            
    $to $event->getTo();
            
    $from $event->getFrom();
            
    $dx $to->$from->x;
            
    $dy $to->getY() - $from->getY();
            
    $dz $to->getZ() - $from->getZ();
            
    $to->setComponents($from->getX() - $dx$to->getY(), $from->getZ() - $dz);
            
    $event->setTo($to);
        }   
    }
    [/QUOTE]
  4. aliuly
    Offline

    aliuly Notable Member Plugin Developer

    Joined:
    Feb 8, 2014
    Posts:
    1,086
    Plugins:
    17
    Yes, forgot...

    Change the :
    PHP:
      $to $event->getTo(); 
    to

    PHP:
      $to = clone $event->getTo(); 
    However, you still need to check for collisions... i.e. if there is a wall where you are heading to, it will glitch into it.
  5. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    It won't be fluent anyway. Motions are first handled in MCPE then PocketMine. In that way it is only possible to teleport/boost the player to the opposite direction, which has terrible visual performance.

    Also, you should handle EntityMotionEvent rather than PlayerMoveEvent.
  6. Misaka05323
    Offline

    Misaka05323 New Member

    Joined:
    Dec 17, 2014
    Posts:
    5
    Minecraft User:
    Misaka05323
    It worked!But just as the Floor 4 said,it had a terrible visual performance.Anyway,thank you very much!
    PEMapModder likes this.
  7. Misaka05323
    Offline

    Misaka05323 New Member

    Joined:
    Dec 17, 2014
    Posts:
    5
    Minecraft User:
    Misaka05323
    YES,the event happened first in the Minecraft ,then the event would be passed to PocketMine.The delay give the player a bad experience.
  8. aliuly
    Offline

    aliuly Notable Member Plugin Developer

    Joined:
    Feb 8, 2014
    Posts:
    1,086
    Plugins:
    17
    Yah, it looks more like a "Drunken" walk effect rather than a "Chaos direction"

Share This Page

Advertisement