Trying to make baby zombies attack other zombies?

Discussion in 'Plugin Development' started by thok13, Feb 19, 2013.

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

    thok13

    Code:
    @EventHandler
        public void onTargetSwitch(EntityTargetLivingEntityEvent e)
        {
            if(e.getEntityType() == EntityType.ZOMBIE)
            {
                Zombie zombie = (Zombie) e.getEntity();
                Entity target = e.getTarget();
                if(zombie.isBaby())
                {
                    Block targetBlock = zombie.getTargetBlock(null, 50);
                    for(Entity e1 : targetBlock.getChunk().getEntities())
                        if (e1.getType() == EntityType.ZOMBIE) {
                            zombie.setTarget((LivingEntity) e1);
                    }
                    if(target.getType() == EntityType.PLAYER)
                    {
                        Player player = (Player) target;
                        if(player.hasPermission("mlz.safe"))
                        {
                            e.setCancelled(true);
                        }
                    }
                }
            }
        }
    This code appears to not be working. The baby zombies don't attack other zombies. They also don't attack players with "mlz.safe", so I know I'm doing something right. Any help would be nice :D

    Sorry for bumping but I need help :(

    If you read this please help me :'(

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

    RealDope

    Use e.setTarget(), not zombie.setTarget()
     
  3. Offline

    thok13

    tried that, but I get errors. This is my code:
    Code:
    Block targetBlock = zombie.getLocation().getBlock();
                    for(Entity e1 : targetBlock.getChunk().getEntities())
                    {
                        Bukkit.getServer().dispatchCommand((CommandSender) Bukkit.getServer(), "say found" + e1.getType().toString());
                        if (e1.getType() == EntityType.ZOMBIE) {
                            e.setTarget((LivingEntity) e1);
                            e.setCancelled(false);
                        }
                    }
    
    Did I do something wrong?
    edit: this: Bukkit.getServer().dispatchCommand((CommandSender) Bukkit.getServer(), "say found" + e1.getType().toString()); was causing problems. I took it out but still wont work

    HELP ME

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

    Deckerz

    Right so what you have done is made a infinite loop of targeting, make the for loop so that once it targets one zombie it breaks the loop

    Also you may need to create a repeater thing so that it keeps setting the target

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

    thok13

    What do you mean repeater? I made it break but that didn't help
     
  6. Offline

    Deckerz

    a scheduled task
     
  7. Offline

    Tim Visee

Thread Status:
Not open for further replies.

Share This Page