Animal Flowing player

Discussion in 'Plugin Development' started by Razdom, Mar 8, 2014.

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

    Razdom

    Hay!
    I'm trying to create an animal that follows the player.
    I tried to teleport the animal evry 5 secend but is not looking god.
    how can i create flow?
     
  2. Offline

    tamajpm

    Something with setLeathHolder?
     
  3. Offline

    Razdom

    No without Leath
     
  4. Offline

    GameplayJDK

    If it is hostile (Zimbie, ...) you can listen to the EntityAttackEvent (, I think it was called like that,) and cancel it. Hostile mobs will follow any player (, but i think they can be told to target a specific one,) but not attack them.
    The disadvantage is, that the mob you chose to follow the player can be any in the wolrd.
    So you have to do some metadata stuff and attach things like name / ... to it.
    In the event use an if statement to check if the mob should attack or not.
     
  5. Offline

    tamajpm

    Maybe you can cast the mob into a LivingEntity and set the target?
     
  6. Offline

    GameplayJDK

    Razdom

    Code:java
    1.  
    2. // Code by GameplayJDK // Based on craftbukkit-1.7.2-R0.3
    3. public void makeZombieFor(Player player) {
    4. LivingEntity zombie = (LivingEntity) player.getWorld().spawnEntity(new Location(player.getWorld(), player.getLocation().getX(), player.getLocation().getY(), player.getLocation().getZ()), EntityType.ZOMBIE);
    5. zombie.setCustomName("Owner: " + player.getName());
    6. zombie.setCustomNameVisible(false);
    7. }
    8.  
    9. @EventHandler
    10. public void onTryTargetOtherThanOwner(EntityTargetEvent event) {
    11. if (event.getTarget() instanceof Player && event.getEntity() instanceof Zombie) {
    12. LivingEntity zombie = (LivingEntity) event.getTarget();
    13. Player player = (Player) event.getEntity();
    14. String zombieId = zombie.getCustomName();
    15. if (zombieId.equalsIgnoreCase("Owner: " + player.getName())) {
    16. event.setTarget(player);
    17. }
    18. }
    19. }
    20.  
    21. @EventHandler
    22. public void onTryAttackOwner(EntityDamageByEntityEvent event) {
    23. if (event.getEntity() instanceof Player && event.getDamager() instanceof Zombie) {
    24. LivingEntity zombie = (LivingEntity) event.getDamager();
    25. Player player = (Player) event.getEntity();
    26. String zombieId = zombie.getCustomName();
    27. if (zombieId.equalsIgnoreCase("Owner: " + player.getName())) {
    28. event.setCancelled(true);
    29. }
    30. }
    31. }
    32.  
     
  7. Offline

    CraftThatBlock

    What I did: Make a zombie and disguise it as a sheep or something using LibsDisguise (or whatever plugin you like the most). It will follow you, and you can cancel the damage event to it doesn't hurt you. LibsDisguise also takes care or sounds for you.
     
    GalaxyBeatzz likes this.
  8. Offline

    GameplayJDK

    Btw. The code I posted in my last post is untested! It's not error proof, but it should do the thing. :)
     
  9. Offline

    Razdom

    I try to use cow...
     
  10. Offline

    Garris0n

    Sounds easier to just give it a custom pathfinder...
     
  11. Offline

    Razdom

    Garris0n
    im try it:
    Code:java
    1. mob = new MobDisguise(DisguiseType.COW,true,true);

    its work but the cow is not baby...
    why?

    Edit:
    Oops its false not true...
     
Thread Status:
Not open for further replies.

Share This Page