How do I summon a Zombie that doesn't attack me but attacks the other players?

I am working on a Minecraft map and I came across this. I am trying to make a special ability so that you can summon a Zombie that doesn't attack you but attacks the other players.


Solution 1:

A mob will not try to attack you if you are on the same team as it. For example, you can create a team:

/scoreboard teams add FriendlyMobs

Then add yourself and the zombie to the team:

/scoreboard teams join FriendlyMobs @p @e[type=Zombie]

You could also summon the zombie already on the team:

/summon Zombie ~ ~ ~ {Team:"FriendlyMobs"}

Solution 2:

You could set up a contraption where it keeps the zombie away from you. Summon the zombie with a CustomName like this:

/summon Zombie ~ ~ ~ {CustomName:"NoAttackZombie"}

and then keep it away from you like this:

/execute {Your Name} ~ ~ ~ execute @e[type=Zombie,name=NoAttackZombie,r=2] ~ ~ ~ tp @e[type=Zombie,name=NoAttackZombie,r=1] ~1 ~ ~

So basically when the zombie gets close to you, it will constantly teleport 1 block away from you within a 2 block radius. However, all other players that are not running the execute command will not teleport the zombie away.