Different Types of Damage

Discussion in 'Plugin Development' started by Acer_Mortem, Aug 5, 2014.

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

    Acer_Mortem

    Hello! In my plugin, I would like to create different types of damage, such as Regular and Special. Players will have Regular and Special Defence Stats, that will reduce the damage for each kind of attack.

    A special attack might be whirlwind, in which nearby entities are damage, such as like this:

    Code:
    for(Entity e : attacker.getNearbyEntities(5, 5, 5){
        if(e.isDamagable()){
              e.damage(5, attacker); //This is the Special Attack here.
        }
    }
    This code would call the EntityDamagebyEntityEvent, for 5 damage and the attacker being "attacker". However, how could I discern this kind of attack from a Regular attack (such as just swinging your sword)?

    In essence, my question is this:

    How could I be able to send information along with the EntityDamagebyEntityEvent in the event that it's called specially (such as in the above snippet of code)?

    or, would there be a better way of going around and modifying an entities health based on various attacks, completely bypassing the EntityDamagebyEntityEvent for Special Attacks?

    Simply setting the new mobs health as 5 less than it's previously does not work, as Bukkit does not register that the attacking Player is the last damager.
     
  2. Offline

    fireblast709

    Acer_Mortem how is a special attack performed (code wise)
     
  3. Offline

    Acer_Mortem

    fireblast709

    A special attack would be performed like this:

    Code:
    @EventHandler
    public void whirlWind(PlayerInteractEvent e){
        if(e.getPlayer().getItemInHand().getType().equals(Material.STICK)){
              for(Entity e : e.getPlayer().getNearbyEntities(5, 5, 5){
                  e.damage(5, e.getPlayer(); //this is the Special Attack.
              }
        }
    }
    What I would like for the above method to do would be to be for the damage line to be considered "Special," and therefore lower the damage due to the Entities Special Defence stat. Instead, this line would call the EntityDamagebyEntityEvent, from which there would be no way to determine that this attack was any different than that from a regular sword swing.
     
  4. Offline

    fireblast709

    Acer_Mortem before the for loop, set a flag to show that the Player is performing the whirlwind special attack, and after the attack remove the flag. Then, in EntityDamageByEntityEvent, simply check for that flag.

    A flag just is an indication whether they are executing a skill. Think about using Metadata for this, or your own HashMap/Set/custom object
     
  5. Offline

    Acer_Mortem

    fireblast709

    That's a very smart idea..

    Also, if you don't mind I have two other questions:

    1. Do you know any other better way of storing persistent data with ItemStacks than simply using the Lore?
    2. Is there anyway to extend for example Arrows. For exmaple, I would have a SuperArrow that would extend Arrow, have the same characteristics of Arrow, and could be used for Arrow methods (such as Player.launchProjectile(SuperArrow))?
     
  6. Offline

    fireblast709

    Acer_Mortem likes this.
Thread Status:
Not open for further replies.

Share This Page