[NEED HELP] with spawning an entity

Discussion in 'Plugin Development' started by skillerfox3, Jul 15, 2014.

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

    skillerfox3

    Hello everyone!

    I wrote a script that has to spawn a few (not one) zombies if a small fireball hits the ground. the fireball has to fire if you interact the air with a Cactus green dye.

    How do I spawn the zombie1? And how do I spawn multiple of them?

    Thanks for helping!

    Code:java
    1. // Spawn Zombie spawn ball level 1 //
    2. public void zombie1(PlayerInteractEvent e) {
    3. Player p = e.getPlayer();
    4. if (p.getItemInHand().getType() == Material.INK_SACK
    5. && p.getItemInHand().getTypeId() == 2) {
    6. p.launchProjectile(SmallFireball.class);
    7. }
    8. }
    9.  
    10. // Zombie spawn ball level 1 //
    11. @SuppressWarnings("deprecation")
    12. public void zombie1e(EntityExplodeEvent e) {
    13. if (e.getEntity().getType() == EntityType.SMALL_FIREBALL) {
    14.  
    15. Zombie zombie1 = (Zombie) e.getLocation().getWorld().spawnEntity(e.getLocation(), EntityType.ZOMBIE);
    16.  
    17. zombie1.setCustomName(ChatColor.RED +"Invader");
    18. zombie1.setCustomNameVisible(true);
    19. zombie1.getEquipment().setHelmet(Lhelmet);
    20. zombie1.getEquipment().setHelmet(Lchestplate);
    21. zombie1.getEquipment().setHelmet(Lleggings);
    22. zombie1.getEquipment().setHelmet(Lboots);
    23. zombie1.getEquipment().setItemInHand(Wsword);
    24.  
    25. }
    26. }
     
  2. Offline

    THEREDBARON24

    Firstly, make sure to annotate EventHandler. After this, I assume that the zombie spawns. If it doesn't, check settings regarding the regulation of mob spawning. Finally, you are setting the helmet 4 times. I believe that you want to set other parts of his equipment. To spawn multiple zombies, you can place all the code regarding the zombie in a while loop. Create an int with the amount of zombies that you want to spawn, and then subtract one per iteration of the loop. Hope this helps
     
  3. Offline

    Hadenir

    Try to use this code:
    Code:java
    1. // Spawn Zombie spawn ball level 1 //
    2. @EventHandler
    3. public void zombie1(PlayerInteractEvent e) {
    4. Player p = e.getPlayer();
    5. if (p.getItemInHand().getType() == Material.INK_SACK
    6. && p.getItemInHand().getTypeId() == 2) {
    7. p.launchProjectile(SmallFireball.class);
    8. }
    9. }
    10.  
    11. // Zombie spawn ball level 1 //
    12. @SuppressWarnings("deprecation")
    13. @EventHandler
    14. public void zombie1e(EntityExplodeEvent e) {
    15. if (e.getEntity().getType() == EntityType.SMALL_FIREBALL) {
    16.  
    17. Zombie zombie1 = (Zombie) e.getLocation().getWorld().spawnEntity(e.getLocation(), EntityType.ZOMBIE);
    18.  
    19. zombie1.setCustomName(ChatColor.RED +"Invader");
    20. zombie1.setCustomNameVisible(true);
    21. zombie1.getEquipment().setHelmet(Lhelmet);
    22. zombie1.getEquipment().setHelmet(Lchestplate);
    23. zombie1.getEquipment().setHelmet(Lleggings);
    24. zombie1.getEquipment().setHelmet(Lboots);
    25. zombie1.getEquipment().setItemInHand(Wsword);
    26.  
    27. }
    28. }

    It may can fix your problem.
     
Thread Status:
Not open for further replies.

Share This Page