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

Throwing TNT

Discussion in 'Development' started by Jonas, Mar 4, 2017.

  1. Jonas

    Jonas Baby Zombie

    Messages:
    192
    How can i make Throwing TNT?
     
  2. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    spawn a TNT with motion when player try to do a certain action that indicates it's trying to throw the tnt
     
  3. Jonas

    Jonas Baby Zombie

    Messages:
    192
  4. BEcraft

    BEcraft Slime

    Messages:
    79
    GitHub:
    BEcraft
    PHP:
      $nbt = new CompoundTag("", [
                                
    "Pos" => new ListTag("Pos", [
                                    new 
    DoubleTag(""$player->x),
                                    new 
    DoubleTag(""$player->$player->getEyeHeight()),
                                    new 
    DoubleTag(""$player->z)
                                ]),
                                
    "Motion" => new ListTag("Motion", [
                                    new 
    DoubleTag("", -sin($player->yaw 180 M_PI) * cos($player->pitch 180 M_PI)),
                                    new 
    DoubleTag("", -sin($player->pitch 180 M_PI)),
                                    new 
    DoubleTag(""cos($player->yaw 180 M_PI) * cos($player->pitch 180 M_PI))
                                ]),
                                
    "Rotation" => new ListTag("Rotation", [
                                    new 
    FloatTag(""$player->yaw),
                                    new 
    FloatTag(""$player->pitch)
                                ]),
                                ]);
                            
    $f 2;
                            
    $tnt Entity::createEntity("PrimedTNT"$player->chunk$nbttrue);
                            
    $tnt->setMotion($tnt->getMotion()->multiply($f));   
                            
    $tnt->spawnTo($player);
    Just be sure to define $player
     
    artulloss likes this.
  5. Jonas

    Jonas Baby Zombie

    Messages:
    192
    In which Event? And what must i write to use pocketmine\...
     
  6. BEcraft

    BEcraft Slime

    Messages:
    79
    GitHub:
    BEcraft
    Whatever you want xD
    I meant use it how you need
     
  7. BEcraft

    BEcraft Slime

    Messages:
    79
    GitHub:
    BEcraft
    For example
    PHP:
    public function onInteract(PlayerInteractEvent $e){
    $player $e->getPlayer();
    If(
    $e->getItem()->getId() == 313){
     
    $nbt = new CompoundTag("", [
                                
    "Pos" => new ListTag("Pos", [
                                    new 
    DoubleTag(""$player->x),
                                    new 
    DoubleTag(""$player->$player->getEyeHeight()),
                                    new 
    DoubleTag(""$player->z)
                                ]),
                                
    "Motion" => new ListTag("Motion", [
                                    new 
    DoubleTag("", -sin($player->yaw 180 M_PI) * cos($player->pitch 180 M_PI)),
                                    new 
    DoubleTag("", -sin($player->pitch 180 M_PI)),
                                    new 
    DoubleTag(""cos($player->yaw 180 M_PI) * cos($player->pitch 180 M_PI))
                                ]),
                                
    "Rotation" => new ListTag("Rotation", [
                                    new 
    FloatTag(""$player->yaw),
                                    new 
    FloatTag(""$player->pitch)
                                ]),
                                ]);
                            
    $f 2;
                            
    $tnt Entity::createEntity("PrimedTNT"$player->chunk$nbttrue);
                            
    $tnt->setMotion($tnt->getMotion()->multiply($f));   
                            
    $tnt->spawnTo($player);
    $player->sendMessage("Hi mom");
    }
    }
     
  8. Jonas

    Jonas Baby Zombie

    Messages:
    192
    CompoundTag not found
     
  9. BEcraft

    BEcraft Slime

    Messages:
    79
    GitHub:
    BEcraft
    Use
    use pocketmine\nbt\tag\CompoundTag;
    use pocketmine\nbt\tag\ListTag;
    use pocketmine\nbt\tag\ByteTag;
    use pocketmine\nbt\tag\DoubleTag;
    use pocketmine\nbt\tag\FloatTag;
     
  10. Jonas

    Jonas Baby Zombie

    Messages:
    192
    It dont work. Rcon says 'pocketmine\event\player\PlayerInteractEvent' and 'pocketmine\entity' not founded but it there.
    PHP:
    <?php

    namespace Main;

    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\nbt\tag\CompoundTag;
    use 
    pocketmine\nbt\tag\ListTag;
    use 
    pocketmine\nbt\tag\ByteTag;
    use 
    pocketmine\nbt\tag\DoubleTag;
    use 
    pocketmine\nbt\tag\FloatTag;
    use 
    pocketmine\event\player\PlayerInteractEvent;
    use 
    pocketmine\entity;
    use 
    pocketmine\event\Listener;

    class 
    PrimedTNT extends PluginBase implements Listener {
        
        public function 
    onEnable(){
            
    $this->getServer()->getPluginManager()->registerEvents($this$this);
        }
        
         public function 
    onInteract(PlayerInteractEvent $e){
             
    $player $e->getPlayer();
             if(
    $e->getItem()->getId() == 46){
                 
    $nbt = new CompoundTag("", [
                                
    "Pos" => new ListTag("Pos", [
                                    new 
    DoubleTag(""$player->x),
                                    new 
    DoubleTag(""$player->$player->getEyeHeight()),
                                    new 
    DoubleTag(""$player->z)
                                ]),
                                
    "Motion" => new ListTag("Motion", [
                                    new 
    DoubleTag("", -sin($player->yaw 180 M_PI) * cos($player->pitch 180 M_PI)),
                                    new 
    DoubleTag("", -sin($player->pitch 180 M_PI)),
                                    new 
    DoubleTag(""cos($player->yaw 180 M_PI) * cos($player->pitch 180 M_PI))
                                ]),
                                
    "Rotation" => new ListTag("Rotation", [
                                    new 
    FloatTag(""$player->yaw),
                                    new 
    FloatTag(""$player->pitch)
                                ]),
                                ]);
                            
    $f 2;
                            
    $tnt Entity::createEntity("PrimedTNT"$player->chunk$nbttrue);
                            
    $tnt->setMotion($tnt->getMotion()->multiply($f));   
                            
    $tnt->spawnTo($player);
                            
    $player->sendMessage("Hi mom");
           }
        }
    }
     
  11. BEcraft

    BEcraft Slime

    Messages:
    79
    GitHub:
    BEcraft
    use pocketmine\entity\Entity;
     
  12. Jonas

    Jonas Baby Zombie

    Messages:
    192
    Thanks it work :)
     
  13. BEcraft

    BEcraft Slime

    Messages:
    79
    GitHub:
    BEcraft
    You are welcome :D
     
  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.