Solved Hi. I am noob (TNT Drop on player death)

Discussion in 'Plugin Development' started by Liutenantpickle, Nov 10, 2012.

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

    Liutenantpickle

    Waddup bukkit people! I'm developing my first plugin, about Perks. :d
    Here's how it works, when the player dies, it drops a lit TNT from the location where the Player died.

    Code:
    @EventHandler
    public void onDeath(PlayerDeathEvent e){
        Player killed = e.getEntity(); //for death message
        Player killer = e.getEntity().getKiller(); //for death message
        if(killed instanceof Player){
          //TNT drops here
    Can someone hlp me? D:
    Thanks :)
    - Pickle
     
  2. Offline

    Seadragon91

    killed.getWorld().spawnEntity(killed.getLocation(), EntityType.PRIMED_TNT);
     
    Rprrr and Liutenantpickle like this.
  3. Offline

    Liutenantpickle

    Okay thanks, Ill try it :)

    I tried it, and nothing happens :( help?

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

    Woobie

    Did you register the event?
     
  5. Offline

    Liutenantpickle

    What do you mean register? and where?
     
  6. Offline

    Woobie

    In your mean class, put this inside your onEnable method:
    Code:
    getServer().getPluginManager().registerEvents(YourListenerClass, this);
    If you have your event in the main class, do
    Code:
    getServer().getPluginManager().registerEvents(this, this); 
     
  7. Offline

    Liutenantpickle

    Oh damn, I forgot :( Thanks btw, But do I need to implement my class to listener? like this?
    public class Perks extends JavaPlugin implements Listener {
     
  8. Offline

    Woobie

    Yeah.
    Otherwise you cant register the event.
     
  9. Offline

    Liutenantpickle

    OMG its working! Thanks :D
    but is it possible to decrease the TNT's explosion delay?
     
  10. Offline

    Seadragon91

    Do this to have the entity in a variable:
    TNTPrimed tnt = (TNTPrimed) killed.getWorld().spawnEntity(killed.getLocation(), EntityType.PRIMED_TNT);

    Take a look at here:
    http://jd.bukkit.org/apidocs/org/bukkit/entity/TNTPrimed.html

    There are 2 method to get and to set the ticks until the tnt explode. I testet it and standard are 80 ticks (20 ticks = 1 second as info, I am not sure if you know that)

    80 ticks = 4 seconds
    60 ticks = 3 seconds
    40 ticks = 2 seconds

    Good luck
     
    Liutenantpickle likes this.
  11. Offline

    Liutenantpickle

    HA! Thanks Seadragon and Woobie!
    Is this alright?

    Code:
        @EventHandler
        public void onDeath(PlayerDeathEvent e) {
            Player killed = e.getEntity();
            if (killed instanceof Player) {
                TNTPrimed tnt = (TNTPrimed) killed.getWorld().spawnEntity(killed.getLocation(), EntityType.PRIMED_TNT);
                tnt.setFuseTicks(10);
            }
        }
    }
     
  12. Offline

    Seadragon91

    Do you tried it? 10 ticks = 0.5 seconds, very short :)
     
  13. Offline

    Liutenantpickle

    Yeah, I like it that way :3 Thanks btw :D
     
Thread Status:
Not open for further replies.

Share This Page