Get percentage of damage done to a mob

Discussion in 'Plugin Development' started by CullanP, Oct 7, 2014.

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


    What I'm trying to do is get how much damage is done to a certain mob (zombie) with a custom set name, but I have no idea on how I could achieve this. I'm thinking EntityDamageByEntityEvent, but I don't see a way that could store damage done to the mob by different players and return the percentage of damage each player did back so I could customize the drop table for this certain mob. Much help or any hints would be appreciated.
  2. Offline


    Using a proportion:

    [​IMG] 1 damage is equal to 5% so full health (20 hearts) = 100% and 15 hearts = 75%, etc.

    I'm doing something quite close to what you are doing :p
  3. Offline


    Store it with a HashMap of players and integers, and to get the percentage of damage out of 100, multiply the damage by 5.
    CullanP likes this.
  4. Offline


    1. int health = (int) p.getHealth();
    2. int max = (int) p.getMaxHealth();
    3. double percent = health/max;
    4. p.sendMessage("Your health is at " + percent + "%.");
  5. Offline


    Alright, so I'm having issues thinking of a way to count different players ints separately through the hashmap. If player1 hits a mob and deals 5 damage, and player2 hits the mob and deals 5 damage, player2 will have 10damage in hashmap when he should have 5, Much help would be appreciated, here's my code

    1. public static HashMap<Player, Double> MobDamagePercentage = new HashMap<Player, Double>();
    2. double damage = 0;
    4. @EventHandler
    5. public void entitydamage(EntityDamageByEntityEvent e) {
    6. if (e.isCancelled()) {
    7. return;
    8. }
    9. for (Double dmg : MobDamagePercentage.values()) {
    10. dmg = e.getFinalDamage();
    11. damage += dmg;
    12. }
    13. if (e.getDamager() instanceof Player) {
    14. Player p = (Player) e.getDamager();
    15. MobDamagePercentage.put(p, damage);
    16. p.sendMessage(MobDamagePercentage.toString()); //Debug messages
    17. p.sendMessage(Double.toString(damage));
    18. }
    19. }

    Bump: Please help

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: Jun 14, 2016
  6. Offline


    CullanP You have the "damage = 0 "
    so if you set it to de final damage it will update
    "damage = 5 "
    so next time when a player gives damage to something it will add the final damage again to
    "damage = 10 "
    Thats why it puts the second player in the map to 10
    You should set the damage "damage = 5 " to 0. at the end of the event
Thread Status:
Not open for further replies.

Share This Page