Custom NPCs
This tutorial I will show how to make a custom npc. If you don't know the basics of command blocks go to this tutorial and come back. There is a button that will take you to back to this page don't worry.
Okay first we need to make a scoreboard for villager clicked. Not too hard scoreboard objectives add VillagerClick minecraft.custom:minecraft.talked_to_villager is that out of the way.
Before we proceed summoning a villager is necessary to make as the npc. Here is the so summon villager ~ ~1 ~ {CustomNameVisible:1b,NoAI:1b,CustomName:"{\"text\":\"name\"}",Offers:{}}. I will quickly break down all those attributes. The villager has no ai so we can give it ai. The villager has a custom name and we make it visible. We also make sure it has no offers so that when we right click it we don't get his trade menu. That can be done with leaving offers blank.
​
Lets quickly talk about villager movement. For some reason both teleport and tp seem to be relative to whos executing (you are the command block). Key word executing. That means if we use an execute command and specify the "at" at them then we can tp relative to them. Command will look like this execute as @e[type=villager,name=name] at @s run tp @s ~ ~ ~ ~ ~. We do need both at and as unfortunately. Well lets talk about the tildas and what they do when we adjust them. The first three are there x, y and z. I assume everyone knows about those. The second two are yaw and pitch. Yaw the first one of the two is their rotation around the y axis. If you are looking down yaw will rotate from east to south, from south to west, from west to north and from north to east. I hope that makes sense if not just experiment. Negatives can be used to specify the reverse effect. You specify in degrees. Last is pitch. This is how far up or down your are looking. Up is negative and down is negative. Also in degrees.
​
Okay now onto text. If you have seen my youtube video the first lot of command blocks are just building up to the last two sets so I will only cover the last two. First we need a scoreboard scoreboard objectives add name dummy is just the trick. First command we will do will allow for the changing and functionality of this role. The command is execute at @e[type=villager,name=name] run scoreboard players add @a[scores={VillagerClick=1..},distance=..5] name 1. This command will add 1 score to your objective for every click. The ".." after "VillagerClick=1" is optional but I prefer to have it incase they have been clicking some non-npc villagers. Now lets make use of this objective. execute as @e[type=villager,name=name] run tellraw @a[scores={VillagerClick=1..,name=x}] {"text":"<name> text"} is the command to do so. There are alot of italics so I will quickly go over them. The first name is the name of your npc. The second name is the name of your objective which I recommend to be the same as your npc. X is the order number of the text. 1 will be the first time you click, 2 the second etc. The third name is the name of your npc, this can change but I recommend it to be the same because when you type in chat the name that appears is the name above your head so same should work with custom npcs. The last one is text and is the text you want your npc to say. One last command before we go on to the next section of the npcs and that command is scoreboard players set @a VillagerClick 0. This command will set your villager click score to 0. If you have seen my magic carpet you will see this familiar as its what I used for my sneak. You always want the score to reset even if it executed or not.
​
Last thing before we go is choice. You should be able to interact with these characters so now we can. First we want some text to come up so we know what we are replying to. For simplicity I won't hook it up to what we worked on in the last paragraph so here it is execute at @e[type=villager,name=name] run tellraw @a[scores={VillagerClick=1..},distance=..5] {"text":"<name> text"}. Now we need our options to come up. I will only do one option for simplicity but feel free to add as many as you want. Command is here execute at @e[type=villager,name=name] run tellraw @a[scores={VillagerClick=1..},distance=..5] {"text":"[option]","color":"color","clickEvent":{"action":"run_command","value":"/tellraw @p {\"text\":\"<name> text\"}"}}. Again a lot of italics so I will go through them all briefly. All names relate are the villagers name. The last one doesn't matter about typos as it will still run it just won't look good to people using it. Then option is what you will be saying I prefer to have square brackets but those are also optional. See what I did there? Okay I'll stop. Color is color but be careful they have to be one of the 16 colours spelt exactly how I have them "aqua", "black", "blue", "dark_aqua", "dark_blue", "dark_grey", "dark_green", "dark_purple", "dark_red", "gold", "gray", "green", "light_purple", "red", "white" and "yellow". They are case and spelling sensitive and there are no other colors so beware. Also color is us not uk spelling. Same with a lot of things.
​
That is it for this article! I hope I was able to hope you out! If I did something wrong, you have any improvements or something else to add altogether be sure to message me with the box in the bottom right of your screen that has been annoying you since you first opened this website.