How would I go about setting a entity as an ally to a player, such that, they won't target them, but will target all other players?
Tupay It should accept a boolean value to set either if it is tamed or not. And it's for Tameable entities like Horses, Ocelots, Wolves and to assign the owner, it would be: Code:java entity.setOwner(Player name);
That would only work for Wolves, Ocelots and Horses however, my primary use would be Zombies and Skeletons, however they do not implement Tameable. /ninja'd
I believe you should use EntityTargetEvent, then check if the entity is a player, then write your other code in there. Code:java @EventHandlerpublic void onTarget(EntityTargetEvent e) { if(e.getTarget() instanceof Player) { Player target = (Player) e.getTarget(); if(blahblah.contains(target.getName())) { e.setCancelled(true); } }}
No, if blahblah contains the target, it would cancel the every single time the entity keeps targeting the player, it works, i've tested it out. if you want a certain entity to not attack the player, check the entity with e.getEntity();
I mean, wouldn't it ATTEMPT to retarget the same player, and never attack another player, because it's trying the same player first, if you understand what I mean. I can't test it right now because it would involve 2 players
if it re-targets the player, it would cancel it, if that's what you're saying. But if it targets someone else, it wont cancel that.
If there is 2 players in the entities range, and the closest one is 'allied' with it, it will keep targetting and cancelling that one, since it's closest, it will never even attempt to target the other player, even though if it did, it would actually target it.
Oh I see what you're saying. I'm going to test it out right now. If it goes like you said it would, then there's another option called e.setTarget(Entity ent), I can set the target if it doesn't work, but I think it should Nope, it works perfectly, try it out. EDIT by Moderator: merged posts, please use the edit button instead of double posting.
I personally just created my own entity class that extends one of the original entities and overwrote the findTarget method. I'm not sure you need to do something so complicated, but I found that repeatedly cancelling the entitytargetevent was inefficient and sometimes unreliable.
It doesn't even seem like it is constantly targeting the entity, then canceling it. I think it cancels it once and then moves on to another player/entity. However, if it is inefficient, like I said, you can also check the closest player near you and use e.setTarget(Entity e) {} and set the target yourself.