Making Firework Do Damage

Discussion in 'Plugin Development' started by superjesse07, Nov 9, 2013.

Thread Status:
Not open for further replies.
  1. I want to know if its possible to make firework do damage i searched hard and i can't find anything please someone help me :(

    Is there Someone around there that knows the answer on my question ferrybig can you help me

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

    TryB4

    superjesse07
    You gotta make a custom firework entity.
    Or you can just

    Code:java
    1. for(LivingEntity en : <firework>.getWorld().getEntitiesByClass(LivingEntity.class)){
    2. if(en.getLocation().distance(<firework>.getLocation()) <= 3)//or your distance{
    3. en.damage(3);
    4. }
    5. }
    6.  
     
  3. If you are able to get the location of the firework when it explodes, you can get al the entities near it, and apply damage to them
    Code:
    final Firework firework = ...;
    new BukkitRunnable(){public void run(){
    if(!firework.isValid){
    this.cancel();
    // Firework just exploded
    final double damage = 20; // Kill a player when he is standing inside the boom
    final int range = 5; // 5 block range
    
    
    final int squaredRange = range*range;
    double distance;
    final Location loc = firework.getLocation();
    for(Entity entity : firework.getWorld().getEntities()){if(entity instanceof LivingEntity){
    if((distance = entity.getLocation().distanceSquared(loc)) < squaredRange)
    {
    if(distance < 1) distance=1;
    double damageModifer = ((squaredDistance - distance) / squaredRange) / 100; // This calculation may be better.... (it should apply less damage to the player if he is further away
    double toDamage = damage*damageModifer;
    assert damage >= toDamage;
    ((LivingEntity)entity).damage(toDamage);
    }
    }}
    }}.runTaskTimer(plugin,1,1);
     
  4. ferrybig I'm not good at coding this is my code for the firework can you say em how to add the damage
    Code:
                    Block b = player.getTargetBlock(null, 50);
                    double x = b.getX();
                    double y = b.getY();
                    double z = b.getZ();
                    Firework fw = (Firework) player.getWorld().spawn(b.getLocation(), Firework.class);
                    FireworkEffect effect = FireworkEffect.builder().trail(true).flicker(true).withColor(Color.BLACK).withFade(Color.ORANGE).with(Type.BALL_LARGE).build();
                    FireworkMeta fwm = fw.getFireworkMeta();
                    fwm.clearEffects();
                    fwm.addEffect(effect);
                    Field f;
                    try {
                            f = fwm.getClass().getDeclaredField("power");
                            f.setAccessible(true);
                            f.set(fwm, -2);
                    } catch (NoSuchFieldException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                    } catch (SecurityException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                    } catch (IllegalArgumentException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                    } catch (IllegalAccessException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                    }
             
             
                    fw.setFireworkMeta(fwm);
    i got you on skype and i'm making a sort of empirewand with this
     
  5. I thought you had a firework rocket, in this case, its simple to add a damage, at the following to the end of the code you send:
    Code:
    final double damage = 20; // Kill a player when he is standing inside the boom
    final int range = 5; // 5 block range
    
    
    final int squaredRange = range*range;
    double distance;
    final Location loc = firework.getLocation();
    for(Entity entity : firework.getWorld().getEntities()){if(entity instanceof LivingEntity){
    if((distance = entity.getLocation().distanceSquared(loc)) < squaredRange)
    {
    if(distance < 1) distance=1;
    double damageModifer = ((squaredDistance - distance) / squaredRange) / 100; // This calculation may be better.... (it should apply less damage to the player if he is further away
    double toDamage = damage*damageModifer;
    assert damage >= toDamage;
    ((LivingEntity)entity).damage(toDamage);
    }
    }
    
     
  6. ferrybig i get an error by squared distance please help me how to fix it
     
  7. superjesse07 inside my code, I talked about firework, can you change it to fw?
    also, what is the exact error message you get?
     
Thread Status:
Not open for further replies.

Share This Page