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

Is there away to make Throwing Sword?

Discussion in 'Development' started by xXNiceAssassinlo YT, May 22, 2018.

  1. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    499
    GitHub:
    xXNiceYT
    Is there away making throwing sword making murder mystery plugin!
     
  2. Driesboy

    Driesboy Spider Jockey

    Messages:
    34
    GitHub:
    driesboy
    sure, by spawning an ArmorStand, making it invisible and give it a sword.
     
    corytortoise and RyanShaw like this.
  3. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    also dont forget to animate it's trajectory so it moves

    in command blocks fashion,
    test for fireball with tag,
    if fireball with tag found, set invisible,
    spawn invisible armor stand holding visible sword on
    prefer to anchor/offset on the sword and rotating it flat and making it match so it looks realistic
    now just move the armorstand to the fireball every tick

    in PMMP api you can add a custom entity projectile extending fireball so it go straight with an invisible rotated armorstand holding a sword
    now when someone hold the sword you can spawn the armor stand entity which will shoot the sword straight forever
     
  4. GamakCZ

    GamakCZ Zombie Pigman

    Messages:
    598
    GitHub:
    GamakCZ
    I do not know if it will work.
    PHP:
    /**
         * @param Player $shooter
         */
        
    public function throwSword(Player $player) {
            
    $aimPos $player->getDirectionVector();
            
    $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(""$aimPos->x),
                    new 
    DoubleTag(""$aimPos->y),
                    new 
    DoubleTag(""$aimPos->z)
                ]),
                
    "Rotation" => new ListTag("Rotation", [
                    new 
    FloatTag(""$player->yaw),
                    new 
    FloatTag(""$player->pitch)
                ]),
                
    "Health" => new ShortTag("Health"5),
                
    "Item" => new CompoundTag("Item", [
                    
    "id" => new ShortTag("id"Item::IRON_SWORD),
                    
    "Damage" => new ShortTag("Damage"0),
                    
    "Count" => new ByteTag("Count"1),
                ]),
                
    "PickupDelay" => new ShortTag("PickupDelay"0x7F),
            ]);
            
    $sword Entity::createEntity("Item"$player->getLevel(), $nbt$player);
            
    $sword->setMotion($sword->getMotion()->multiply(1.5));
            
    $sword->spawnToAll();
            
    $player->getInventory()->setItemInHand(Item::get(Item::AIR));
        }
     
  5. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    Ehh, you can cut down on a lot of code (repetition) there. Using Item entity may not be ideal, try a custom ArmorStand class like @Thunder33345 said.

    PHP:
    /** @var Player $player */
    $nbt Entity::createBaseNBT($player->add(0$player->getEyeHeight(), 0), $player->getDirectionVector(), $player->yaw$player->pitch);
    $sword Entity::createEntity("ThrowingKnife"$player->getLevel(), $nbt$player);
    $sword->setMotion($sword->getMotion()->multiply(1.5));
    $sword->spawnToAll();
    The ThrowingKnife class could extend the Projectile class like so.
    PHP:
    class ThrowingKnife extends Projectile{
        public const 
    NETWORK_ID self::ARMOR_STAND;
        
    //dont forget the $width and $height

        
    protected function sendSpawnPacket(Player $player) : void{
            
    parent::sendSpawnPacket($player);
            
    //send MobEquipmentPacket for Iron Sword
        
    }
    }
     
  6. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    dont you have to anchor/rotate so the sword is facing forward and looking in a thrown position?
     
  7. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    Ah, yes. The pose #8 with yaw = relative yaw - 75 seems suitable for a throwing knife. I think you'll need to lock the rotation.
    PHP:
    $nbt Entity::createBaseNBT(
        
    $player->add(0$player->getEyeHeight(), 0),
        
    $player->getDirectionVector(),
        
    $player->yaw 75,//makes the sword point straight, instead of towards the right
        
    $player->pitch
    );

    //initEntity()
    $sword->getDataPropertyManager()->setByte(Entity::DATA_ARMOR_STAND_POSE_INDEX8);
    rr.PNG
     
    Last edited: May 22, 2018
  8. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    499
    GitHub:
    xXNiceYT
    Can we despawn the sword?

    Because it’s a entity
     
  9. LewBr

    LewBr Zombie

    Messages:
    385
    GitHub:
    lewbr
    What you mean?
     
  10. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    499
    GitHub:
    xXNiceYT
    $entity->kill()
     
  11. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    $entity->close() should do
    P.S. Use $entity->flagForDespawn() now that it exists.
     
    Last edited: Aug 3, 2018
  12. SleepSpace9

    SleepSpace9 Slime

    Messages:
    78
    GitHub:
    sleepspace9
    or $entity->flagForDespawn() :p
     
  13. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    499
    GitHub:
    xXNiceYT
    Does this still works? For lastest pmmp?
     
  14. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    Sure, it should.
     
  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.