Change the damage of projectile?

Discussion in 'Plugin Development' started by xxNightlordx, Nov 12, 2012.

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

    xxNightlordx

    I would like to change the damage of a snowball when it hits.
     
  2. Offline

    Vandrake

    entitydamagebyentityevent
    if damager instanceof Snowball
    set the damaged person's health -amount you want
    profit
     
  3. almost.
    this is better:
    inside the entitydamagebyentityevent
    Code:
            if(event.getCause() == DamageCause.PROJECTILE){
                if(event.getDamager() instanceof Snowball){
                    if(event.getEntity() instanceof Player){
                        event.setDamage(2); // one heart of damage
                    }
     
  4. Offline

    Vandrake

    how is this better?You added a line
     
  5. Offline

    desht

    It's better because he's using the event API to correctly report back to CraftBukkit how much damage should be done by this event. EntityLiving can then process the incoming damage just like any other damage event.

    (Checking to see if the victim is a Player isn't necessarily required - you might want to allow snowballs to damage creatures too...)
     
  6. Offline

    Vandrake

    just to check I understood:
    its better to use Damage instead of the sethealth relative?
     
  7. Offline

    desht

    In general I would say yes. Let CraftBukkit process the damage normally, and deal with things like damage reduction by armour, etc. On the other hand, there may be times when you do need to modify the player's health directly - it's a design consideration, really.
     
  8. Offline

    Vandrake

    Hmmm. Understood xD Thank you for the explanation
     
  9. Offline

    xSICKxXxBOWLZx

    Hi sorry this is like over a year and a half old post and im replying, but would you know what do to, to remove health without armour affecting it? I am new to coding and im guessing you would start with p.getHealth(); and then removing a certain amount but im not sure.
     
Thread Status:
Not open for further replies.

Share This Page