Knockback player, but have minimal damage

Discussion in 'Plugin Development' started by iBecameALoaf, Apr 8, 2014.

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

    iBecameALoaf

    Hi! I'm working on a plugin, where all players basically have a total of 1000 health, (not really, I'm just damaging a player 10 damage, and dividing it by 50, so that they have to be hit 100 times to die). It's working fine, except there is no knockback. This is how I do the damage:

    Code:
    event.setDamage(0.0);
                        damagePlayer(damager, (Player) event.getEntity(), 10.0,
                                false);
    Code:
        public static void damagePlayer(Player damager, Player player,
                double damage, boolean message) {
            player.damage(damage / 50);
            if (message == true) {
                damager.sendMessage("§aYou §7» " + player.getName() + "§7 for §a"
                        + damage + "§7 damage.");
                player.sendMessage("§c" + damager.getName() + "§7 » "
                        + player.getName() + "§7 for §c" + damage + "§7 damage.");
     
            }
        }
    Any ideas of how I can get this to work? I'm also pretty sure you can hit players way more than you should in a certain amount of time. (That's why I need the knockback)
     
  2. Offline

    skyrimfan1

    I haven't tested this, but you could theoretically do:
    Code:
    public void addKnockback(Player player, double multiplier, double height) {
         double negative = Math.abs(multiplier) * -1;
         Vector current = player.getLocation().getDirection();
         double x = current.getX();
         double y = current.getY();
         double z = current.getZ();
         x *= negative;
         y *= height;
         z *= negative;
         current.setX(x).setY(y).setZ(z);
         player.setVector(current);
    }
     
  3. Offline

    coasterman10

    When you call player.damage(damage / 50), you need to provide a source entity. When a source entity is provided, the knockback will be provided as normal.
    Code:java
    1. player.damage(damage / 50, damager);
     
  4. Offline

    iBecameALoaf

    I'll try this, thanks!

    This just causes the server to time out... ?
     
  5. Offline

    coasterman10

    Is this happening within the player damage event code? If so, then this is causing an infinite loop, since that damage method will call another EntityDamageByEntityEvent, thus calling it again, and again, ad infinitum until your server crashes. If this is being done on every EntityDamageByEntityEvent, it's best just to use event.setDamage(...) and leave it at that.
     
  6. Offline

    iBecameALoaf

    even when I use event.setDamage, there is no knockback :O
     
  7. Offline

    coasterman10

    iBecameALoaf What event are you listening for? It might also be useful to post the full event code to see if something else is happening.
     
Thread Status:
Not open for further replies.

Share This Page