Solved Damage Player relative to distance of Entity

Discussion in 'Plugin Development' started by Poppi, Apr 11, 2014.

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

    Poppi

    This may be more of a math question, however I wondered how I could make it so the closer the player is to an entity/block the more damage he takes when I decide to fire an event (done that part)

    Essentially what Im asking is how to make this work in the way that TNT does; the closer you are the more damage you take. (I dont want to spawn any tnt)
     
  2. Offline

    St3venAU

    Code:java
    1. Location l = // the location of your entity or block
    2. double base = // damage you want a player to take if they are at the exact coordinates of the entity/block
    3. double multiplier = // the amount you want the damage to decrease for each block the player is away
    4. double damage = base - multiplier*player.getLocation().distance(l);
    5. if(damage>0)
    6. player.damage(damage);
     
    Lorinthio likes this.
  3. Offline

    Lorinthio

    You could get the player location, compare it to the location of the block to get a distance, and create either a formula or a lot of if statements to give a damage then either damage the player with the damage event or do straight damage with sethealth

    What st3ven said... You ninja haha

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

    Poppi

    Thanks!
     
Thread Status:
Not open for further replies.

Share This Page