Ammunition & Length

Discussion in 'Plugin Development' started by XKnucklesX, Aug 23, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    XKnucklesX

    Hello Everyone I am a developer of a plugin. I am having requests of letting the bullets from the guns be able to be changed. I am having trouble thinking of a way to make this work.

    Here is the piece of code that tells the gun the ammo.:
    Code:java
    1. private void Gun1(Player p) {
    2. Snowball sb = (Snowball) p.getWorld().spawn(p.getEyeLocation(), Snowball.class);
    3. sb.setShooter(((LivingEntity) p));
    4. sb.setVelocity(p.getLocation().getDirection().multiply(1.0));
    5. }


    This makes the ammo snowball. How do I make it any entity they want. Also the number 1.0 I need that to be able to be changed. Not sure how to.

    Any ideas?
     
  2. XKnucklesX
    Your questions make no sense.

    For launching projectiles, use
    Code:
    p.launchProjectile(Snowball.class);
    unless you want to modify the velocity, if so, use your current code, but change the double value to whatever is appropriate. This brings me to one of your problems; "I need that to be able to be changed".. as in? Just increase/decrease the value.

    If you want the velocity to be defined within calling the method, then add a parameter to the constructor.
    Code:
    private void Gun1(Player p, double vel)
    Now replace '1.0' with 'vel'.

    If you want to get the velocity from config, then use its getDouble() method.
    Code:
    double vel = getConfig().getDouble("path.to.double");
    For the ammo, before shooting, check if the player inventory contains at least 1 of the ammo material, and upon shooting, remove 1 ammo from the inventory. You can use the methods I showed above, if you want to somehow define the ammo required, but instead of double, use Material or String, depending on the situation.
     
  3. Offline

    XKnucklesX

    No I mean changed from the config Assist sorry for not making it clear.
     
  4. XKnucklesX
    Could you elaborate your other questions too? It'd be much easier to help, if I knew what you need help with.
     
Thread Status:
Not open for further replies.

Share This Page