Get armor points

Discussion in 'Plugin Development' started by tomjw64, Mar 30, 2012.

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

    tomjw64

    Right now in a plugin of mine (MaxHealth), I am having to manually add a players armor points up every time they are damaged with several switches checking their armor inventory slots. Is there a faster way to do this or is there eventually going to be a faster way?
     
  2. Offline

    geekygenius

    You could just cancel the player damage event and the Armour wouldn't break.
     
  3. Offline

    tomjw64

    It's not a matter of breaking or not breaking. It's a matter of factoring in armor for it's effect on damage.
     
  4. Offline

    CorrieKay

    player.getInventory().getArmorContents()[x].getDurability()

    getARmorContents() returns an array of item stacks, so you can use a for loop such

    for(ItemStack i : armorContents()){
    //code here
    }
     
  5. Offline

    Technius

    We need player.calculateDamageReduction();

    I'd actually like to implement Armor skills into SkyrimRPG....
     
  6. Offline

    CorrieKay

    it shouldnt be too dificult to figure out. i dont think that the armors total durability is ever taken into consideration, only how many armor points they have total.
     
  7. Offline

    tomjw64

    Yeah, it's based on the points, not the durability, thanks for the response though.

    I agree, or at least a quick, one method way of accessing a players total armor points.
     
  8. Offline

    Technius

    tomjw64
    CorrieKay

    Actually, I used info from the Minecraft wiki to come up with a small and cheap way.
    Code:java
    1. public double getDamageReduced(Player player)
    2. {
    3. org.bukkit.inventory.PlayerInventory inv = player.getInventory();
    4. ItemStack boots = inv.getBoots();
    5. ItemStack helmet = inv.getHelmet();
    6. ItemStack chest = inv.getChestplate();
    7. ItemStack pants = inv.getLeggings();
    8. double red = 0.0;
    9. if(helmet.getType() == Material.LEATHER_HELMET)red = red + 0.04;
    10. else if(helmet.getType() == Material.GOLD_HELMET)red = red + 0.08;
    11. else if(helmet.getType() == Material.CHAINMAIL_HELMET)red = red + 0.08;
    12. else if(helmet.getType() == Material.IRON_HELMET)red = red + 0.08;
    13. else if(helmet.getType() == Material.DIAMOND_HELMET)red = red + 0.12;
    14. //
    15. if(boots.getType() == Material.LEATHER_BOOTS)red = red + 0.04;
    16. else if(boots.getType() == Material.GOLD_BOOTS)red = red + 0.04;
    17. else if(boots.getType() == Material.CHAINMAIL_BOOTS)red = red + 0.04;
    18. else if(boots.getType() == Material.IRON_BOOTS)red = red + 0.08;
    19. else if(boots.getType() == Material.DIAMOND_BOOTS)red = red + 0.12;
    20. //
    21. if(pants.getType() == Material.LEATHER_LEGGINGS)red = red + 0.08;
    22. else if(pants.getType() == Material.GOLD_LEGGINGS)red = red + 0.12;
    23. else if(pants.getType() == Material.CHAINMAIL_LEGGINGS)red = red + 0.16;
    24. else if(pants.getType() == Material.IRON_LEGGINGS)red = red + 0.20;
    25. else if(pants.getType() == Material.DIAMOND_LEGGINGS)red = red + 0.24;
    26. //
    27. if(chest.getType() == Material.LEATHER_CHESTPLATE)red = red + 0.12;
    28. else if(chest.getType() == Material.GOLD_CHESTPLATE)red = red + 0.20;
    29. else if(chest.getType() == Material.CHAINMAIL_CHESTPLATE)red = red + 0.20;
    30. else if(chest.getType() == Material.IRON_CHESTPLATE)red = red + 0.24;
    31. else if(chest.getType() == Material.DIAMOND_CHESTPLATE)red = red + 0.32;
    32. return red;
    33. }


    It returns a double. For example, if you have full armor points, it reduces 80%. So the method returns 0.8. It's pretty useful, I guess.
     
    Lactem, KingFaris11, Bartoke and 2 others like this.
  9. Offline

    CorrieKay

    good stuff!
     
  10. Offline

    TheTrixsta

    why not create the function :D
     
    Technius and CorrieKay like this.
  11. Offline

    tomjw64

    Yeah, that's what I'm doing right now, but with integers and a switch. :/
     
  12. Offline

    Technius

    I'm too lazy to fork it and make a pull request.
     
    tomjw64 likes this.
  13. Offline

    tomjw64

    Respect gained.
     
    Technius likes this.
  14. Offline

    TheTrixsta

    i could start a small library for everything you could want to do with armour :D
    ill think about it
     
Thread Status:
Not open for further replies.

Share This Page