NPCs Creation
In this tutorial, that comes after A First Look, Part 1 and A First Look, Part 2 we will see how we can add NPCs in the RPG Creation Kit and how they exist in the project.
The process is very easy and straightforward, so let's get right into it.
NPCs as Prefabs
In the RPG Creation Kit, NPCs exists as prefabs inside your project. To have NPCs inside your cells, you may place those prefabs directly in the corresponding scenes or you may instantiate them at runtime.
Unless for specific reasons (as we've seen for the Thief in the previous tutorial) you should always place them while composing your scenes.
If you have an NPC inside your scene, you're able to assign more settings to him by using the Inspector, as compared to the Rck AI Editor Nevertheless, if you are going to modify something that is present inside the Rck AI Editor, you should always do it from there, as it will edit the Prefab and not the instance you have in the scene.
Before going foward, focus on the Cell View and open the scene "Virrihael(0,-2)", we are going to place the NPC by the lake and make him sit on the chair that's there.
Creating the NPC
If you want to create a new NPC, you are always going to use the Rck AI Editor. You can open it by clicking on the top-menu "RPG Creation Kit -> Rck AI Editor".
There are two ways you can create an NPC, from scratch or by duplicating an existing NPC. We are going to create him from scratch.
Right click in the left-list, while not hoovering on a button, and select "New":
This will add a new element in the list at the very top of it, named "_New_RckAI". Click on it and let's configure it.
Select the Entity ID, which is the ID of this NPC and pick a name for him.
I'll have:
ID: Uriel001
Name: Uriel
If you're wondering why I always add '001' at the end of every ID, it's because of two things, the first one is that If I look at it I can instantly tell it is an ID, the second thing is that during the creation of your game you may have variations of the same NPC, as it happens for "Ryan" in the Demo. So you can differentiate versions of NPCs with the number '001', '002'...
Next, pick the Race, at this point you should only have one, unless you created new races. Select "Human" and take a look at the window.
I'm, gonna leave the "IsMale" cheked since my NPC will be a male, the rest is really upon to you, see the explaination for each field in the Rck AI Editor article.
I'll leave everything untouched and switch to the "Face" tab, where I'll edit his face and select Hair and Eyes for him.
Next, in the "Inventory" tab you'll pick all the items you want this NPC to carry, and if he dies, to loot on his body.
You'll notice that the arrow will appear right to every item, the arrow is used to make the NPC equip the selected item, that will be present also in the "Equipped Items" list. You should only equip ARMOR and Weapons, and have only one weapon an armor piece equipped at time, other situations, such has having 2 sword in the Equipped list, have an undefined behaviour.
I'll have him equip the Iron Set (Curiass, Gloves, Pants, Boots) and the Steel Greatsword:
In next tab, you're asked to select the Behaviour and Dialogue of the NPC.
For the Behaviour, as we said previously we want him to sit on the chair. Since this behaviour is cell-dependent (the chair he has to sit on exists only in the Virrihael(0,-2) cell, we'll set it into the Instance of the prefab later. For now, select as purpose Behaviour "[BTree][P] EmptyState". This means that everytime the NPC will be instantiated, unless specifically changed, he will have the EmptyState behaviour.
For the Combat Behaviour, select "Full Combat_Forced".
For the Current and Default dialogue, I'm going to set it to the "GenericEmpty" dialogue.
And we're done.
Click on "SAVE" and then on "SELECT PREFAB" on the top.
Put the prefab inside the scene and now you need to build an habit.
Everytime you change something inside a Cell that is accessible by ID, such as adding/removing AI, adding/removing NPC Action Points, doors or any other element that has an ID, you need to Update the Cell. You can do this by selecting the "CellInfo" GameObject inside the cell, and click in the inspector "Update Cell". What this will do, is to simply ensure the Cell is correctly configured, that every ID->Reference exists and every GameObject is at his place.
Great, now let's load the game and reach that Cell (just go South from the City gates).
You can see that you will be able to do with him most of the Interactions you've done with others in the Demo, because that's it, that's how NPCs are created and added in the world. You can talk with him, he will look at you and if you attack him he will fight back.
However, you'll notice that he's standing still and not sitting on the Chair we made for him. That's because we've set him the "EmptyState" Behaviour, and we said we want to modify the instance of the prefab, not the prefab itself.
So let's go ahead and make him sit on the Chair. load up again the "Virrihael(0,-2)" cell and focus on him, then let's take a look at the RckAI Inspector. Switch to the "Behaviour" tab, because that's what we need to modify and let's change his Purpose Behaviour to be "SBTP_UseCurrentActionPoint". This Purpose Behaviour will make the NPC, use his Current Action Point.
Perfect, the last thing to need to do is to choose his Current Action Point, we'll do that in the "Movements" tab, scroll down to "NPCActionPoint" and select the "WoodenChair..." that appears in the list.
Save the scene and we're done.