Equip Zombies by Spawning

Discussion in 'Plugin Development' started by Xilence, Jun 24, 2013.

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

    Xilence

    Hello everyone,
    I create a new Plugin and I want to know how to equip Zombies by spawning.
    LG Xilence :)
    Code:
    @EventHandler
     
        public static void Creaturespawn(CreatureSpawnEvent event){
         
          if(event.getCreatureType().getTypeId() == CreatureType.ZOMBIE.getTypeId()){
              event.setCancelled(true);
             
             
          }
         
        }
    My code so far
     
  2. Offline

    adam753

    What you've got here will check when a zombie spawns and then stop it from spawning, so you'll get no zombies at all. But you probably knew that.
    The first thing you want to do is:
    Code:
    Zombie zombie = (Zombie)event.getEntity();
    
    That will give you the zombie that spawned, so that you can do things to it. Note that this is only safe to do after the line where you check if it's a zombie, otherwise you could be casting anything to a Zombie which will give you lots of errors.
    After that, you can do anything to it, for example:
    Code:
    zombie.teleport(new Location(0,64,0)); //Teleports the newly-spawned zombie
    
    For a full list of things you can do to your zombies, check out this documentation page, or in Eclipse you can just type "zombie." and wait for intelliSense to show you the list of methods.

    Don't forget to remove the line which cancels the event!
     
  3. Offline

    joehot2000

    zombie.getEquipment().setItemInHand(Material.STONE_SWORD);

    I think.
     
Thread Status:
Not open for further replies.

Share This Page