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

How do I make a player sit with DataPacket?

Discussion in 'Development' started by rektpixel, Oct 23, 2017.

  1. rektpixel

    rektpixel Baby Zombie

    Messages:
    186
    How do I make a player sit.? Packets have been changed in PocketMine and old chair plugins don't work. I found this edit of a plugin by Jasonwynn on the forums which is probably my best hope of fixing it:
    PHP:
    <?php
    namespace maru;

    use 
    pocketmine\entity\Entity;
    use 
    pocketmine\Server;


    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\event\server\DataPacketReceiveEvent;
    use 
    pocketmine\network\mcpe\protocol\AddEntityPacket;
    use 
    pocketmine\event\player\PlayerInteractEvent;
    use 
    pocketmine\network\mcpe\protocol\ProtocolInfo;
    use 
    pocketmine\block\Stair;
    use 
    pocketmine\network\mcpe\protocol\RemoveEntityPacket;
    use 
    pocketmine\network\mcpe\protocol\SetEntityLinkPacket;
    use 
    pocketmine\math\Vector3;
    use 
    pocketmine\network\mcpe\protocol\types\EntityLink;

    class 
    PmChair extends PluginBase implements Listener{
        public 
    $counter = [];
        public 
    $count 0;
        public function 
    onEnable(){
            
    $this->getServer()->getPluginManager()->registerEvents($this$this);
            
    $this->count 10000;

        }
        public function 
    onPacketReceived(DataPacketReceiveEvent $event){
            
    $pk $event->getPacket();
            switch(
    $pk::NETWORK_ID){
                case 
    ProtocolInfo::PLAYER_ACTION_PACKET;
                    
    $player $event->getPlayer();
                    if(isset(
    $this->counter[$player->getName()])){
                        if(
    $pk->action === 8){$ppk = new SetEntityLinkPacket();
                            
    $ppk->from $this->counter[$player->getName()];
                            
    $ppk->to 0;
                            
    $ppk->type 0;
                            
    $player->dataPacket($ppk);
                            
    $pkc = new SetEntityLinkPacket();
                            
    $pkc->from $this->counter[$player->getName()];
                            
    $pkc->to $player->getId();
                            
    $pkc->type 0;
                            
    $ps Server::getInstance()->getOnlinePlayers();
                            
    Server::getInstance()->broadcastPacket($ps,$pkc);
                            
    $pk0 = new RemoveEntityPacket();
                            
    $pk0->entityUniqueId $this->counter[$player->getName()];
                            
    $ps Server::getInstance()->getOnlinePlayers();
                            
    Server::getInstance()->broadcastPacket($ps,$pk0);
                            unset(
    $this->counter[$player->getName()]);
                        }
                    }
            }
        }

        public function 
    onTouch(PlayerInteractEvent $event){
            if(
    $event->getBlock()->getID() === 53){
                
    $player $event->getPlayer();
                
    $pk = new AddEntityPacket();
                
    $this->count $this->count 1;
                
    $pk->entityRuntimeId=$this->count;
                
    $pk->type 86;
                
    $pk->motion = new Vector3();
                
    $block $event->getBlock ();
                if (
    $block instanceof Stair) {
                    
    $pk->position $block->asVector3()->add(0.51.50.5);
                    
    $pk->speedX 0;
                    
    $pk->speedY 0;
                    
    $pk->speedZ 0;
                    
    $pk->yaw $player->yaw;
                    
    $pk->pitch $player->pitch;
                    
    $pk->metadata = [Entity::DATA_FLAGS => [Entity::DATA_TYPE_BYTE<< Entity::DATA_FLAG_INVISIBLE],[Entity::DATA_TYPE_STRING << Entity::DATA_NAMETAG] , [Entity::DATA_TYPE_BYTE,<< Entity::DATA_FLAG_ALWAYS_SHOW_NAMETAG], [Entity::DATA_TYPE_BYTE,<< Entity::DATA_FLAG_NO_AI]];
               
                    
    $ps=Server::getInstance()->getOnlinePlayers();
                    
    Server::getInstance()->broadcastPacket($ps,$pk);
                    
    $ppk = new SetEntityLinkPacket();
                    
    $ppk->from $this->count;
                    
    $ppk->to 0;
                    
    $ppk->type 2;$player->dataPacket($ppk);
                    
    $pkc = new SetEntityLinkPacket();
                    
    $pkc->from $this->count;
                    
    $pkc->to $player->getId();$pkc->type 2;
                    
    $ps=Server::getInstance()->getOnlinePlayers();
                    
    Server::getInstance()->broadcastPacket($ps,$pkc);
                    
    $this->counter[$player->getName()] = $this->count;
                }
            }
        }
    }
    This had a couple of errors which I fixed but the big issue with this is something to do with putEntityLink ?:eek:
    Code:
    [22:34:20] [Server thread/CRITICAL]: Could not pass event 'pocketmine\event\player\PlayerInteractEvent' to 'PmChair v1.3': Argument 1 passed to pocketmine\network\mcpe\protocol\DataPacket::putEntityLink() must be an instance of pocketmine\network\mcpe\protocol\types\EntityLink, null given, called in phar://C:/Users/Admin/Creative Cloud Files/Desktop/Server/Server - DEV/PocketMine-MP.phar/src/pocketmine/network/mcpe/protocol/SetEntityLinkPacket.php on line 43 on maru\PmChair
    [22:34:20] [Server thread/CRITICAL]: TypeError: "Argument 1 passed to pocketmine\network\mcpe\protocol\DataPacket::putEntityLink() must be an instance of pocketmine\network\mcpe\protocol\types\EntityLink, null given, called in phar://C:/Users/Admin/Creative Cloud Files/Desktop/Server/Server - DEV/PocketMine-MP.phar/src/pocketmine/network/mcpe/protocol/SetEntityLinkPacket.php on line 43" (EXCEPTION) in "src/pocketmine/network/mcpe/protocol/DataPacket" at line 533
    
    When the player taps block ID 53 it needs to sit them on it, please help me do this :)
     
  2. alexwolf_dev

    alexwolf_dev Spider Jockey

    Messages:
    43
    GitHub:
    Frago9876543210
    PHP:

    public function onClick(PlayerInteractEvent $e){
       if(
    $e->getItem()->getId() !== 280 || $e->getAction() !== $e::RIGHT_CLICK_BLOCK){
          return;
       }
       
    $block $e->getBlock();
       
    $player $e->getPlayer();
       
    $player->setMotion(new Vector3(00.20));

       
    $add = new AddEntityPacket;
       
    $add->entityRuntimeId 666;
       
    $add->type 95;
       
    $add->position = new Vector3($block->0.3$block->1.7$block->0.3);
       
    $player->dataPacket($add);

       
    $link = new SetEntityLinkPacket;
       
    $link->link = [666$player->getId(), 11];
       
    $player->dataPacket($link);
    }
     
    rektpixel likes this.
  3. rektpixel

    rektpixel Baby Zombie

    Messages:
    186
    Thanks!
    But why does it get block 280 at the start?:eek:
     
  4. HBIDamian

    HBIDamian HBIDamian Staff Member

    Messages:
    365
    GitHub:
    HBIDamian
    If you right click with the item "stick" equipt, then it runs whatever...
     
    rektpixel likes this.
  5. rektpixel

    rektpixel Baby Zombie

    Messages:
    186
    How do I make it allow only being able to tap the block 53 to sit on it
    this..?
    PHP:
        public function onTouch(PlayerInteractEvent $event){
            if(
    $event->getBlock()->getID() === 53){
                  
    $block $event->getBlock();
                  
    $player $event->getPlayer();
                  
    $player->setMotion(new Vector3(00.20));
                
                  
    $add = new AddEntityPacket;
                  
    $add->entityRuntimeId 666;
                  
    $add->type 95;
                  
    $add->position = new Vector3($block->0.5$block->1.5$block->0.5);
                  
    $player->dataPacket($add);

                  
    $link = new SetEntityLinkPacket;
                  
    $link->link = [666$player->getId(), 11];
                  
    $player->dataPacket($link);
            }
        }
        
     
  6. rektpixel

    rektpixel Baby Zombie

    Messages:
    186
    oh it works but is there a way to remove the popup that appears when the player sits on the chair? "action.hint.exit.area_effect_cloud"
     
    MC ATECH likes this.
  7. alexwolf_dev

    alexwolf_dev Spider Jockey

    Messages:
    43
    GitHub:
    Frago9876543210
    This is client side message
     
    MC ATECH likes this.
  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.