Damage Question - Percent of Damage Dealt?

Discussion in 'Plugin Development' started by xWatermelon, Jul 13, 2013.

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

    xWatermelon

    I was wondering how I can determine the percentage of damage one player dealt to another. It's in those KitPVP servers: "You received x credits for doing y% of the damage to player!". How can I accomplish this?
     
  2. Offline

    xTrollxDudex

    xWatermelon
    You check if event.getDamager() and event.getEntity() are instanceof Player on EntityDamageByEntity event
    Create fields for: event.getDamage()(which is a double)
    Send a message to ((Player) event.getEntity())

    The message will be: "you have received " + x + " credits for doing " + <the damage field>/10.0 + "% damage to " + (Player) event.getEntitiy()

    X will be a calculation of credits based on damage.
     
  3. Offline

    xWatermelon

    xTrollxDudex well I know how to do that, but I was wondering how to show that message when a player you dealt damage to died. It will send you a message that shows the percentage of the total damage that you dealt to a specific player. LazyLemons did you code the one that was on Mc-Kits?
     
  4. Offline

    xTrollxDudex

    xWatermelon
    Exactly, send
    Code:java
    1. ((Player) event.getDamager()).sendMessage(/*message*/);
     
  5. Offline

    soulofw0lf

    use the on damage to add players and damage values to a map that's stored in a map keyed to the players name the damage was dealt to, use the on death event to call the name from that map and get all the players saved to it with keySet() and then add the total damage from all players in that map together, find the percent that each player did of the total, and send the message / assign credits.
     
    xWatermelon likes this.
  6. Offline

    chasechocolate

    xWatermelon I know what you are talking about. For this, you're going to need to log 2 things: the amount of damage players do to each other and the total health of players. For the first one, you're going to need a HashMap<String, HashMap<String, Double>>, the first key being the player name who was damaged, and the HashMap value being the players who dealt the damage and the damage dealt. These values are going to be changed whenever a player gets damaged, I'm assuming you already know how to do that part. For the second variable, you're going to need a HashMap<String, Double> for the total health of the players. Change this variable in an EntityRegainHealthEvent by adding event.getAmount() to the previous value.
     
  7. Offline

    xWatermelon

    Wow, thanks for all your help! If I know the total damage a player dealt and the other players total health then how can I get the percentage dealt?
     
  8. Offline

    xTrollxDudex

    xWatermelon
    Essentially, you will divide the amount of damage dealt by the full health
     
    xWatermelon likes this.
  9. Offline

    xWatermelon

    xTrollxDudex ok! Would I need to multiply it by 100 to get it into a percent (e.g. 70%)?
     
  10. Offline

    xTrollxDudex

  11. Offline

    xWatermelon

    Ok, I'll try it out and see if it works :)
     
Thread Status:
Not open for further replies.

Share This Page