Problems with gun reload. Help please :(

Discussion in 'Plugin Development' started by Serkox, Nov 15, 2016.

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

    Serkox

    Hello, i have a problems with my reload gun system. How to reload of 2 seconds, indicate the number of ammo in the actionbar and check if the player has snowball in the inventory to shoot, if the player doesn't has snowball in the inventory, it does not shoot. If you could give me a model code with explanation, thank you in advance. :)

    Sorry for my english, i am french.
     
  2. Offline

    ipodtouch0218

    No one will spoonfeed you code, but we can improve what you've started.
    Have you tried anything so far?

    This is more difficult. Either use packets, or something like ActionBarAPI
    (maybe an actual api in 1.11 bukkit? its in vanilla now :p)

    Schedulers

    Code:
    Player#getInventory()#contains(Material material, [optional] int amount);
     
  3. Offline

    Serkox

    @ipodtouch0218
    I started this code but i have no idea how to continue it :/

    A yes also i'm in 1.8.


    Code:
        @EventHandler
        public void onPInteract(PlayerInteractEvent e){
            Player p = e.getPlayer();
            Action a = e.getAction();
            ItemStack it = e.getItem();
            int cooldownTime = 2;
            int nbmunsniper = 8;
           
            if(a == Action.LEFT_CLICK_AIR){
                if(nbmunsniper == 0);
                   
                    
                   
                    if(cooldowns.containsKey(p.getName())) {
                        long secondsLeft = ((cooldowns.get(p.getName())/1000)+cooldownTime) - (System.currentTimeMillis()/1000);
                        if(secondsLeft>0) {
                           
                            p.sendMessage("Vous rechargez, vous devez attendre "+ secondsLeft +" secondes!");
                            return;
                        }
                    }
                  
                    cooldowns.put(p.getName(), System.currentTimeMillis());
                  
                    return;
               
                }
               
            }
     
  4. Offline

    ipodtouch0218

    What's the ammo? You mentioned snowballs, but do they "load" into the gun item?
    What will reloading do? We don't have much information.

    Code:
                    if(cooldowns.containsKey(p.getName())) {
                        long secondsLeft = ((cooldowns.get(p.getName())/1000)+cooldownTime) - (System.currentTimeMillis()/1000);
                        if(secondsLeft>0) {
                          
                            p.sendMessage("Vous rechargez, vous devez attendre "+ secondsLeft +" secondes!");
                            return;
                        }
                    }
                 
                    cooldowns.put(p.getName(), System.currentTimeMillis());
    If someone right clicks while the time is still not recharged, it will replace the current "cooldowns" and replace it with the new one. Add an "else" statements to the if, and put "cooldowns.put(p..." inside of it.
     
  5. Offline

    Serkox

    Yes, I did the code for the snowballs in another class.
     
  6. Offline

    HeartandSoul

    So its an object? No?

    I'd make the gun an object, then call new instances of it when you need to
     
Thread Status:
Not open for further replies.

Share This Page