Shoot projectiles at a set fire rate

Discussion in 'Plugin Development' started by Epicballzy, Oct 21, 2014.

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

    Epicballzy

    Hello fellow developers, I've been working on making a Gun plugin for the fun of coding, and I was wondering if it was possible to shoot projectiles (Snowballs, EnderPearls) at a set fire rate. (Shots a second)

    I currently have a Gun object, which will be used to create multiple guns, with their own styles (Machine Guns, Shotguns, Pistols..etc), and I have a method for setting the guns fire rate. But I am not sure how to shoot the projectiles at the specified rate.

    Code:java
    1. public void setFireRate(int shotsASecond) {
    2. this.shotsASecond = shotsASecond;
    3. //What would be put here?
    4. }

    In place of the comment that was set, is that where I would be shooting the projectile from, with my specified rate? Is there some other way to set the fire rate?

    If any other code is needed, just ask.
    Thanks!
     
  2. Offline

    RingOfStorms

    Schedulers!
     
  3. Offline

    Epicballzy

    RingOfStorms Would schedulers create lag if many players were constantly shooting different gun types?
     
  4. Offline

    RingOfStorms

    depends on what code you put in and how you do it. You could alternatively do it on the playerinteract event which is continually called when the player is holding right click on certain items. Then just check the time last fired to the current time and cancel if it is sooner than the fire rate.
     
  5. Offline

    teej107

    Epicballzy
    If you can use System.getCurrentTimeMillis() method, that way is better than using schedulers. But from another post I helped someone with, apparently the PlayerInteractEvent only fires a maximum of every 4 ticks.
     
Thread Status:
Not open for further replies.

Share This Page