Tutorial How to use Durability on Items

Discussion in 'Resources' started by Poprit, Dec 13, 2015.

?

Was this good for a first tutorial?

  1. Yes

    33.3%
  2. It helped me alot!

    16.7%
  3. No

    33.3%
  4. You suck m8

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

    Poprit

    Hello everyone, my name is Poprit.
    I've been coding for a little over three years, and this is my first post on bukkit.
    I replied to a comment on an API called "GunsAPI." The OP of the comment was asking how to create gun 'clips' or 'magazines.' I told him ITEM DURABILITY. It's extremely simple and easy to use.
    I'm going to not be providing a full tutorial but, a mini one with a few methods. For a better idea on how to use these methods you can view my comment here.
    Methods
    Code:
    
    ItemStack is = e.getItem();
    int uses = is.getDurability();
    int full = 20;
    if(uses == 0)
    {
    // yay! Time to reload.
    if(e.getPlayer().getInventory.contains(Your ammo itemstack)
    {
    e.getPlayer.getInventory.remove(Your ammo itemstack);
    is.setDurability((short) 20);
    // send reloaded message
    }
    return;
    }else if(uses > 20)
    is.setDurability((short) 20);
    // Shoot code
    return;
    }else
    {
    // Shoot code
    return;
    }
    

    That is my first tutorial with some rough methods. Remember to view my comment to see how to use them!
    Sincerely
    - Poprit
    EDIT:
    You will have to put this in an interactevent and check if it's your item.
     
  2. Offline

    Poprit

    Thanks for one hundred views guys.
    Remember feedback is welcome!
    Sincerely,
    - Poprit
     
  3. Offline

    mcdorli

    You should really format your code if you make a tutorial. And maybe correct it too. You don't tell the reader, to substract 1 from the current durability either. This tutorial is not usable.
     
Thread Status:
Not open for further replies.

Share This Page