Modifying Armor with Bukkit

Discussion in 'Plugin Development' started by 8thDimension, May 13, 2012.

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

    8thDimension

    Hello, I'm writing a custom server plugin that enables classes and perks. One of the things one of my friends recommended is making it so a certain class takes less damage using a certain armor.

    For example, we have a "warrior" class. If a user is in this class, wearing gold armor will make them take less damage than if they were just a regular player.

    Is there any way on how to lessen how much damage they take? The requirement is that they have to be wearing that full armor set so it won't work unless they wear full gold armor.

    Also, how would I modify how much damage they take? My friend also recommended that they last longer than regular gold armor.

    The first part I can probably figure out on my own, but instead of screwing around and failing miserably, I decided to turn to Bukkit. The latter however I'm stuck on and have no idea.. Perhaps someone the bukkit forums lead me to the right direction?

    Thanks,
    8thDimension
     
  2. Offline

    Tzeentchful

    This is how i would do the the reduced dammage.
    PHP:
    private static Map<PlayerStringclasses = new HashMap<PlayerString>();
     
        @
    EventHandler(priority EventPriority.LOW)
        public 
    void Playerdmg(EntityDamageEvent event){
            if(
    event.getEntity() instanceof Player){
                
    Player player = (Playerevent.getEntity();
                if(
    classes.containsKey(player)){
                    if(
    classes.get(player).equals("warrior")){
                        
    int startdmg event.getDamage();
                        
    int finaldmg = (int) (startdmg 0.5);// 1/2's the dammage
                        
    event.setDamage(finaldmg);
                    }
     
                }
            }
        }
    I would store all the players with their classes in a hashmap then when they get damaged it changes the damage they receive()by 1/2 in the example above.
     
  3. Offline

    8thDimension

    That's very similar to what I was using before.
    I guess I'll just read up in the javadocs and just add in something to check their armor.

    Would you have any idea on how to do the second part though?

    Bump?

    I can't give much, but I'll give my love to those that can help :c

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 25, 2016
  4. Offline

    r0306

    8thDimension
    Did you need help in checking their armor or setting the damage values?
     
  5. Offline

    8thDimension

    Setting the damage values.

    To restate what I would like help on:
    How would one go about making armor stronger when under certain circumstances? Like for example, someone under a "warrior" class.. When they have gold armor it lasts longer
     
  6. Offline

    r0306

    8thDimension
    Well you could always set a custom durability level for the armor. (Make it go up instead of down).
    Code:
    public onPlayerDamage(PlayerDamageEvent event) {
    PlayerInventory i = event.getPlayer.getInventory();
    if (i.getBoots() == Material.GOLD_BOOTS && i.getInventory().getHelmet() == Material.GOLD_HELMET && ...//you get the idea) {
    i.getBoots().setDurability((short) (i.getBoots().getDurability + 1));
    i.getHelmet().setDurability((short) (i.getHelmet().getDurability + 1));
    //... and so on
    //then you would check the Durability of each item in order to see if its broken.
    if (i.getBoots().getDurability == ((short) (i.getBoots().getDurability + <your durability here>)) {
    i.getBoots().setType(Material.AIR);
    }
    if (i.getHelmet().getDurability == ((short) (i.getHelmet().getDurability + <number of hits you want to sustain>)) {
    i.getBoots().setType(Material.AIR);
    }
    }
    }
    
    Of course one huge problem with this is that if the player loses their helmet or something else, they will have an extremely high durability armor. You may have to manually track this in a hashmap or file OR you can do this for every type of gold armor but just set higher durability if the player has a complete set of armor.
     
Thread Status:
Not open for further replies.

Share This Page