Need Help With Making A Smoke Grenade

Discussion in 'Plugin Development' started by SmokyMiner, Oct 24, 2012.

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

    SmokyMiner

    Im trying to make a smoke grenade, and what I have so far just produces a tiny puff of smoke. I want it to produce a cloud of smoke the is large enough to provide decent cover.

    Here's the code:

    Code:
    if(evt.getAction() == Action.RIGHT_CLICK_AIR && evt.getPlayer().getItemInHand().getType() == Material.TORCH)
            {
                    final Player bobi = evt.getPlayer();
                    bobi.getInventory().removeItem(new ItemStack[] {new ItemStack(50, 1) });
                    final World world = bobi.getWorld();
                    final Item smoke = world.dropItem(bobi.getEyeLocation(), new ItemStack(Material.TORCH));
                    smoke.setVelocity(bobi.getEyeLocation().getDirection());
                    plugin.getServer().getScheduler().scheduleAsyncDelayedTask(plugin, new Runnable()
                    {
     
                                @Override
                                public void run() {
                                    final Location loc = smoke.getLocation();
                               
                                    final Location loc1 = loc;
                                    final Location loc2 = loc;
                                    final Location loc3 = loc;
                                    final Location loc4 = loc;
                                   
                                    loc1.setX(loc1.getX() + 2);
                                    loc2.setX(loc2.getX() - 2);
                                    loc3.setZ(loc3.getZ() + 2);
                                    loc4.setZ(loc4.getZ() - 2);
                                   
                                    smoke.getWorld().playEffect(loc, Effect.SMOKE, 1);
                                    world.playEffect(loc1, Effect.SMOKE, 1);
                                    world.playEffect(loc2, Effect.SMOKE, 1);
                                    world.playEffect(loc3, Effect.SMOKE, 1);
                                    world.playEffect(loc4, Effect.SMOKE, 1);
                                   
                                    smoke.remove();
                                }
                            }, 40L);
            }
        }
     
  2. Offline

    kabbage

    You could use a loop to do this. Something like this...
    Code:
    Location loc = null;
            int z = -2;
            int x = -2;
            for(int i = 0; i < 25;i++)
            {
                Location newLoc = new Location(loc.getWorld(), loc.getX() + x, loc.getY(), loc.getZ() + z);
                for(int direction = 0; direction < 8; direction++)
                {
                    loc.getWorld().playEffect(newLoc, Effect.SMOKE, direction);
                }
                if(x == 2)
                {
                    x = 0;
                    z++;
                }
                x++;
            }
     
    SmokyMiner likes this.
  3. Offline

    SmokyMiner

    kabbage
    Edit: My mistake, it works fine, the only thing I need now is to make the smoke's y change just like the x and z do.
     
  4. Offline

    kabbage

    Code:
    Location loc = null;
            int z = -2;
            int x = -2;
            int y = 0;
            for(int i = 0; i < 125;i++)
            {
                Location newLoc = new Location(loc.getWorld(), loc.getX() + x, loc.getY() + y, loc.getZ() + z);
                for(int direction = 0; direction < 8; direction++)
                {
                    loc.getWorld().playEffect(newLoc, Effect.SMOKE, direction);
                }
                if(z == 2)
                {
                    z = -2
                    y++;
                }
                if(x == 2)
                {
                    x = -2;
                    z++;
                }
                x++;
            }
     
  5. sorry, I had just to write this class: http://dev.bukkit.org/paste/6469/ to make the smoke better, (instead of 5 plases where smoke is placed)
    just call the class something like
    Code:java
    1.  
    2. new Smoker(
    3. plugin, // plugin instance
    4. 2, // how many blocks around it need to be smoke
    5. 60, // time in ticks the smoke will last (1 sec = 20 ticks)
    6. 1, // the low limit of smoke partcles every tick
    7. 5, //the high limit of max smoke particles each tick
    8. location // the location object where the smoke must form
    9. ).start();
     
    SmokyMiner likes this.
Thread Status:
Not open for further replies.

Share This Page