How can I tell which villager is being addressed? (Minecraft)?

Ex
5

I'm currently building a map with npc's.

These work by the player clicking on a villager

and the score of Talk to Villager is increased by 1.

Then I ask if a player has the score at 1 and then

a text is played.

The whole thing works fine with a npc.

How can I tell two villagers which villager is clicked on?

(I build in 1.14.3)

Hir the commands:

scoreboard: scoreboard objectives add talkVill minecraft.custom: minecraft.talked_to_villager

Queries: / execute if entity @a [scores = {talkVill = 1.}] Run setblock 470 64 -333 minecraft: redstone_torch replace

A npc: / summon villager ~ ~ 1 ~ {VillagerData: {profession: cleric, level: 2, type: taiga}, Silent: 1, CustomName: "\" Sebastiano \ ""}

Ac

You could mark the villager by working with Execute anchored eyes on you to TalkToVillager = 1, giving him a specific day through raycasting.

Ex

Thank you for your answer.

I have now created the following command:

execute at @e [name = Sebastiano] anchored eyes run say "moin"

The command is always executed, no matter where I'm

(I've never worked with execute anchored)

Ac

Of course it's not that easy.

anchored eyes means that the command is executed from eye level, ie the crosshairs, nothing more. Of course this does not affect commands like / say.

But you can just check with anchored eyes of you at coordinates n ^ after a Villager and mark the. So almost from you each to 0.5; 1; 1.5; 2; 2.5; 3; … In front of you at the corresponding coordinate after a villager in z. For example, test [distance = .0.26] and then give it the day.

The smaller the distances, the more accurate it works. The radius would be a little bit larger than half the distance. And of course you have to stop this testray if he has found something, otherwise other villagers will be marked.

Ex

Thanks for everything I've solved this now:

/ execute at @a as @e [type = minecraft: villager, name = Petty, distance = .5] run setblock 491 64 -322 minecraft: redstone_torch

Ac

Yes, it is also fine. I did not suggest that to you, because in this case Villager must have a gap of more than 10 blocks.