Solved How do you use a different ammo for a bow?

Discussion in 'Spigot Plugin Development' started by dolaking, Feb 13, 2019 at 7:45 PM.

  1. How do you use different ammo for a bow? For example a certain bow uses tnt instead of arrows.
  2. You must spawn the entity(TNT, etc.) and set velocity to entity.
    #2 DeethzzCoder, Feb 13, 2019 at 7:48 PM
    Last edited: Feb 13, 2019 at 8:19 PM
  3. I assume, you'd have to cancel everything regarding the arrow shoot, then spawn an arrow with the same velocity of the arrow you previously canceled. Then, you'd just have to remove 1 tnt from the inventory if any. An alternative would be to allow the consuption of the arrow but a tick later, add an arrow in the inventory but remove 1 tnt. That's what I came up with right now.
    • Like Like x 1
  4. But that way the player would have to have arrows on him to no?
  5. Ah indeed. Ignore what I said. Didn't think of it well enough.
  6. Easiest way would probably to create a "TNT Arrow" sort of item stack and then detecting if a player has that type of arrow in their inventory when they shoot it.

    If you don't want to rerquire the player to have an arrow, what you might be able to do is when the player right clicks with a bow, add an arrow to their inventory to make it so they can pull it back, and then when they shoot modify the arrow as needed.
    • Agree Agree x 1
  7. To bandage the bow, you can check if the player is hold clicking with the bow and if he have a tnt in his inventory then, create a cooldown and add 1 durability to the bow. Then shoot the tnt when the player stop clicking like @Shin1gamiX said
  8. Thanks for all the ideas guys, got it working
  9. Well then, in that case, if they don't have any arrows you could check if they have the required ammo, for example tnt; if they have tnt:
    - add an arrow to the users inventory to allow the pull of the bow (if they have no free space could probably just cache a substitution of an item in their inventory since this whole process will probably take less than 250ms)
    - cancel the shooting, in EntityShootBowEvent, call #getForce() and combine the direction of the shooter, then force shoot off an alternative tnt projectile.
    - then finally if applicable put the substituted item back in the inventory.
    • Agree Agree x 1

Share This Page