Gun Ammo Reloading

Discussion in 'Spigot Plugin Development' started by Drank, Jun 27, 2015.

  1. Hey Spigot,
    I am making a Gun plugin and I am making a reloading + ammo thingy.
    The thing is. It doesn't work. The thing I wanna make is, you have Ammo in your inventory, you reload when youre magsize = 0. (Mag is a HashMap). It loops through the inventory, check how many "Ammo itemstacks" you have. Gets the amount of it. Adds it to the hashmap. (mag) and then removes all of the items.
  2. konsolas


    Hmmm, looks like my mind-reading powers aren't working today.
    • Agree Agree x 1
    • Funny Funny x 1
    • Winner Winner x 1
  3. Just: Looping through inventory to see if he has a itemstack ammo (custom). When he has it, get the amount. And then remove the amount, and put the integer (amount) into the magsize. (hashmap)
    But I dunno how to code it.
  4. konsolas


    What have you tried?

  5. This:

        public void reloading(final Player p, ItemStack ammo, HashMap<UUID, Integer> mag){
            p.sendMessage(v.prefix + "Reloading...");  
            for (int i = 0; i < p.getInventory().getSize(); i++){
                if (p.getInventory().getItem(i) != null && p.getInventory().getItem(i).getType() != Material.AIR){
                    if (p.getInventory().getItem(i) == ammo){
                        int amount = p.getInventory().getItem(i).getAmount();
                        if (amount > mag.get(p.getUniqueId()));
  6. konsolas


    p.getInventory.getItem(i) == ammo -> p.getInventory.getItem(i).getType().equals(ammo.getType())

    And: if(amount > mag.get(p.getUniqueId()));

  7. Yeah, I dunno. Can you write me a good example?
  8. No speenfooding on this forum, sorry.
    Follow konsolas's advises.
  9. konsolas


    Are you an alt.... #PLOTTWIST
  10. sothatsit


    Lmao, alt account which is 25 and female. Normal account which is 14.
  11. Oops, wrong question; do you want some pseudo code? If you don't know; it's code in words, and you have to translate it into real code. ;)
    #11 Svenna, Jun 28, 2015
    Last edited: Jun 28, 2015
  12. Yeah, I would like to have. Hope a start.
  13. Oke.

    Make integer which is 0
    Loop through each itemstack in inventory
    Check if item is the same
    Get amount item and add it int i
    End of the loop you have the amount of all ammo itemstacks in inventory.

    Now, turn it into code ;).