Solved Setting damage of an explosion

Discussion in 'Plugin Development' started by DinoZauruZ, Mar 15, 2015.

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

    DinoZauruZ

    So I want to set the damage on an explosion basically this plugin is for a kit called bomber, when they place tnt with the name §4Bomber it will cancel the event and spawn a TNTPrimed instead, this TNTPrimed gets added to an arraylist and when it blows it cancels the event and creates an explosion the plugin itself works it's a pretty big plugin. And the kit works when they place down the tnt it works as said but the explosion basically only hurts the players around 1 HP...

    Code, I don't think I need to provide code, if you think I should say so :p
     
    Last edited: Mar 15, 2015
  2. Offline

    hopstar

    People don't wanne see your code as proof. They need to read it to see if their is anything weird in it that can cause it.
     
  3. Offline

    Zombie_Striker

    What it sounds like (since I can't see whats wrong) is that its looping through the players that are in a list, and players who are not damaged are not included.

    Debug (e.g. print the names of players affected,health,ect.) and post your code.
     
  4. Offline

    DinoZauruZ

    Code:
    Blockplace:
    Code:
    @EventHandler
        public void onBlockPlace2(BlockPlaceEvent e) {
            if(kitpvp.isinRegion.get(e.getPlayer()) == false) {
                if((e.getBlock().getType() == Material.TNT) &&
                (e.getItemInHand().getItemMeta().getDisplayName().equalsIgnoreCase("§4Bomber"))) {
                    TNTPrimed tnt = e.getPlayer().getWorld().spawn(e.getBlock().getLocation(), TNTPrimed.class);
                    kitpvp.tnts.add(tnt);
                    e.setCancelled(true);
                }
            }
        }
    }
    
    Blockbreak:
    Code:
        @EventHandler
        public void onTNTEXPLODE(EntityExplodeEvent e) {
           
            Entity entity = e.getEntity();
            if(entity instanceof TNTPrimed) {
                TNTPrimed tnt = (TNTPrimed) e.getEntity();
                if(kitpvp.tnts.contains(tnt)) {
                    e.setCancelled(true);
                    e.getLocation().getWorld().createExplosion(e.getLocation().getX(), e.getLocation().getY(), e.getLocation().getZ(), 1f, false, false);
                }
            }
        }
    }
    
     
  5. Offline

    NathanWolf

    Explosion damage is determined by the yield parameter, you're passing in 1 which is a very small explosion. Turn that up to increase damage.

    Explosion damage, I believe, falls off exponentially with distance so keep that in mind.
     
    KingOfTheEast01 likes this.
  6. @DinoZauruZ
    well, you can check on entity damage by entity, if the damager is a PrimedTNT (I believe), it`s an explosion
     
  7. Offline

    DinoZauruZ

    @NathanWolf , nice but I tried that and increased as high as up to 80, and it barely hurts a player it just increases distance, half an heart on 10 blocks away and if you stand inside it it's still the same,


    @Juancomaster1998 , SMART, this was really smart I never thought of it ;) thx I'll try it!

    @Juancomaster1998 Thank you for advice it worked! On the EntityExplodeEvent I just removed the cancel event and cleared the blocklist of exploded blocks, then made an EntityDamagedByEntityEvent and checked if the TNTPrimed was in the arraylist previously mentioned, then damaging the player 3 hearts.
    Code:
    Code:
    @EventHandler
        public void onBomberTntDamagePlayer(EntityDamageByEntityEvent e) {
           
            if(e.getEntity() instanceof Player &&
            e.getDamager() instanceof TNTPrimed) {
                Player p = (Player) e.getEntity();
                TNTPrimed tnt = (TNTPrimed) e.getDamager();
               
                if(kitpvp.tnts.contains(tnt)) {
                    if(p.getHealth() - 6 <= 0) {
                        p.setHealth(p.getHealth() - 6);
                    } else {
                        p.setHealth(p.getHealth() - 6 <= 0 ? 0D : p.getHealth()- 6);
                    }
                }
            }
        }
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 13, 2016
Thread Status:
Not open for further replies.

Share This Page