Applying damage to a player

Discussion in 'Plugin Development' started by bdubz4552, Jul 24, 2013.

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

    bdubz4552

    I'm working on my first plugin, and trying to find a way to apply suffocation damage until the player dies. I have tried creating new instances of entity damage events, but they do nothing at all (I don't even know if this is a proper way of doing it). Any suggestions are much appreciated. Thanks!
     
  2. Offline

    collielimabean

    Yes, you are correct in that you do not want to create new instances of entity damage events. They are used for doing stuff when an event fires, e.g. a cow gets hit by a Player would trigger an EntityDamageByEntityEvent.

    You might want to try (not sure though)
    -Get player from command (/command <player>)
    -Set the remaining air of the player to 0, and continually set that to 0 until the player dies.

    i.e.
    Code:java
    1. while (!player.isDead())
    2. {
    3. player.setRemainingAir(0);
    4. }
     
  3. Offline

    bdubz4552

    I tried this and nothing happened. In trying this though, I found the 'damage()' method for the player object, and tried a 'for' loop to damage until death, but had no effect. Any thoughts?

    Correction: I figured out how do damage the player until death, but need a way to control the rate. As of now, it runs through the loop unrestricted and kills in under a quarter of a second, but I'm aiming to kill the player at the same rate as standard suffocation would. Is there a method that will delay damage for x amount of ticks?
    My 'for' loop: (Please disregard the funky spacing; it pasted in the spacing from Eclipse I think)
    Code:
    for (double var1 = target.getHealth(); !target.isDead(); var1 = var1 - 1) {
                        target.damage(0);
                        target.setHealth(var1);
                    }
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 3, 2016
Thread Status:
Not open for further replies.

Share This Page