Solved bombs of slimeball

Discussion in 'Plugin Development' started by CakeProgrammer, Sep 22, 2013.

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

    CakeProgrammer

    Hello all
    I want to make a plugin that adds bombs from Slimeballs
    I have a code but it is not so good
    There is a problem with
    the problem:
    It does not work like I want (it works more like a landmine) I want it to work like a bomb thrown
    I mean it hurts the block or a player then it explodes and makes a refinery green particles
    My code:
    Code:java
    1. @EventHandler
    2. public void onPlayerClick(PlayerInteractEvent event){
    3. final Player player = event.getPlayer();
    4. if(player.getItemInHand().getType() == Material.SLIME_BALL){
    5. final Item drop = player.getWorld().dropItemNaturally(player.getLocation(), new ItemStack(Material.SLIME_BALL));
    6. drop.setVelocity(player.getLocation().getDirection().multiply(2));
    7. Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
    8. @Override
    9. public void run() {
    10. for(Player player : Bukkit.getOnlinePlayers()){
    11. if(player.getLocation().distance(drop.getLocation()) < 1){
    12. player.damage(4);
    13. }
    14. }
    15. }
    16. }, 15L, 15L);
    17. }
    18. }


    Bump =/

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

    chasechocolate

    I would make the task run more frequently, maybe every 1 or 2 ticks.
     
  3. Offline

    CakeProgrammer

    still not working, I think I've to remove the drop(item) but when I doing
    drop.remove();
    this not working

    Maybe I didn't explain myself enough good,
    what I wanna this "bombs" actually dose, when this hits a player or a block
    this will "explode" and make make damage for the guy that hits the bombs
    if this hits a block this will explode and make damage to the nearby guys (2 blocks)
    my code is up if you need^^
    hope I made it more sense ;)

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 4, 2016
  4. Code:java
    1. @EventHandler
    2. public void TEST(PlayerInteractEvent e)
    3. {
    4.  
    5. final Player p = e.getPlayer();
    6. final Item i = p.getWorld().dropItem(p.getEyeLocation(), new ItemStack(Material.SLIME_BALL));
    7. i.setVelocity(p.getLocation().getDirection().multiply(1.75D));
    8. new BukkitRunnable()
    9. {
    10.  
    11. public void run()
    12. {
    13.  
    14. for(Entity ent : i.getNearbyEntities(1.5D, 1.5D, 1.5D)){
    15.  
    16. if(ent.equals(p))return;
    17. if(!(i.getLocation().getBlock().getRelative(BlockFace.DOWN).getType() == Material.AIR)){
    18.  
    19. i.getWorld().createExplosion(i.getLocation(), 0F);
    20. i.remove();
    21. this.cancel();
    22. return;
    23.  
    24. }
    25. Damageable entity = (Damageable) ent;
    26. entity.damage(4D);
    27. i.getWorld().createExplosion(i.getLocation(), 0F);
    28. i.remove();
    29. this.cancel();
    30. return;
    31.  
    32. }
    33.  
    34. }
    35.  
    36. }.runTaskTimer(plugin, 1L, 0L);
    37.  
    38.  
    39. }


    HOpe that helps
     
  5. Offline

    CakeProgrammer

    testing it, anyways thanks ;)

    this working nice, but this miseed a little bit
    this not always blew up and this not making to me dmg,
    if you can keep help me and make me understand how to do it like I told^^
    then this will be cool
    just to make sense agin,
    I wanna when this hits a block or a player this will make particels and dmg the nearby players,
    not sirsly exlopde ;)

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 4, 2016
  6. CakeProgrammer
    In the code, it will not damage the player that fired and it creates an explosion effect that damages no one. The only thing it damages is the entity it hits dead on. If you want it to damage players in a radius, raise the values in the "getNearbyEntities()".
     
  7. Offline

    CakeProgrammer

    yea I won't wanna explode particels I wanna other, so maybe I should to remove the i.getWorld().createExplosion(i.getLocation(), 0F);
    and put just
    ((Player)ent).damage(2);
    and play my effect?
    this should works?
     
  8. Cake, have an if((!ent instanceof Player))return; before you define went as a player and damage it like one.
     
  9. Offline

    CakeProgrammer

    Solved ty ;)!
     
  10. Np
     
Thread Status:
Not open for further replies.

Share This Page