Setting wolf's target

Discussion in 'Plugin Development' started by Deleted user, Oct 27, 2012.

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

    Deleted user

    So basically in vanilla MC when a player has pet wolf(s) and they meele attack an entity or take damage from an entity their pets will target and attack the threat. Well if you were to attack with say a bow and arrow they will not. I'm trying to accomplish this but I do not know how.

    This is pretty much all I've gotten so far lol..

    Code:java
    1.  
    2. public void onHunterShoot(EntityDamageByEntityEvent event) {
    3. Entity hunter = event.getDamager();
    4. Entity target = event.getEntity();
    5.  
    6. if (!(hunter instanceof Player)) {
    7. return;
    8. }
    9. if (!(event.getDamager() instanceof Arrow)) {
    10. return;
    11. }
    12. if (!HUNTER_LIST.containsKey(hunter.getType().getName())) {
    13. return;
    14. }
    15.  
    16. Player player = Bukkit.getServer().getPlayer(hunter.getType().getName());
    17.  
    18. }
    19.  


    so how do I check to see if the hunter has pets and then set all of his pet's targets to the target.
     
  2. Offline

    sayaad

    Code:java
    1. if(target instanceof Wolf)
    2. {
    3. Wolf w = (Wolf) target;
    4. w.setAngry(true);
    5. w.setTarget(player);
    6. }
     
  3. Offline

    Deleted user

    You clearly did not read my post thoroughly.
     
  4. Offline

    sayaad

    oh whops,

    Use

    w.setAngry(false);
    w.setTarget(null);

    And if that ruturns an NPE then forget the second line.
     
  5. Offline

    Deleted user

    Dude.. I need to get a player's wolves when they attack a player with a bow/arrow and then set their wolves target to the player's target.
     
  6. Offline

    sayaad

    Missed out that part xD moving from 420p to 4k resolution makes stuff hard to read...

    anyway, what you need to do is track every EntityTameEvent and store the entity's unique ID (w.getUniqueId()) along with the players name.

    Where you currently are at in your code, you can loop though that stored id and get IDs where the player's name match up then get the hunter's wolves by that ID and setting its target to null.

    That the only way I'm thinking of doing it, they may be other ways tho.

    Edit :

    Thought of another way.

    Loop through the nearby entitys and if the entity is instanceof Wolf and if the entity != w then set their targets to null. Much better way of doing it but can be buggy.
     
Thread Status:
Not open for further replies.

Share This Page