How can i spawn a new mob 10s after death?

Discussion in 'Plugin Development' started by GaaraKazakage, Jul 17, 2014.

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

    GaaraKazakage

    Hi! Sorry for my bad English :/. I Wanna to do that, when a mob death, spawn a new after 10s. I can how to spawn a new mob, after death, but i cant delay it. I tried it with Scheduler (runTaskLater), but i couldnt use the variables in the run(). Anyone can help me?
     
  2. Offline

    THEREDBARON24

    Listen to the EntityDeathEvent. Then use runTaskLater(){
    public void run(){
    //spawn here.
    }
    }
    if you want to spawn the same entity that died, then you will have to get the type of the entity that was involved with the event and use that with the new mob.
     
  3. Offline

    fireblast709

  4. Offline

    stonar96

    Code:java
    1. @EventHandler
    2. public void onPlayerDeath(final PlayerDeathEvent event) {
    3. plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
    4. @Override
    5. public void run() {
    6. event.getEntity().getWorld().spawnEntity(event.getEntity().getLocation(), EntityType./*mob*/);
    7. }
    8. }, 200L); //10s = 200 ticks
    9. }


    The code is untested.
     
    GaaraKazakage likes this.
  5. Offline

    tommyhoogstra

    dat spoonfeed
     
    AoH_Ruthless and JBoss925 like this.
  6. Offline

    GaaraKazakage

    Thanks stonar96 , with "final", i can do what i want.
     
  7. Offline

    AoH_Ruthless

    GaaraKazakage
    Quick! Explain everything stonar96 just did. If you can't explain every single piece of the code, you aren't ready to use it.
     
    tommyhoogstra and Gater12 like this.
  8. Offline

    stonar96

Thread Status:
Not open for further replies.

Share This Page