Making a NPC - ArtistSaihaan/ArrayRPG-Beta-Godot GitHub Wiki

So far, our player is so lonely and introvert. So let's give him a friend by adding a NPC

NPC's are one of the most crucial part of a rpg. So let's find out how can you make it with ArrayRPG

Scene Setup

Click on the EmptyScene Spatial Node and Ctrl+Shift+A and search for dialogue box. Choose DialogueBox.tscn and you should have a DialogueBox Node in the scene.

Click on the eye button on the side of DialogueBox Node Name to toggle off it's visibility
Now your scene is ready to get a NPC!

Adding and Setting up a NPC

Add a NPC Node inside our Scene and make sure it's a child of the root node (EmptyScene Node)

Add a mesh instance as a child of NPC and set its mesh to whatever you want. (For my case I have chosen a cube!)

Add a collision shape as a child of NPC and set it size to whatever you want.

Add a Area node as it's child and add a collision shape as child of the Area Node. Make sure this collision shape size is greater than the collision shape we added before.
Your NPC should look like this:

Now like most of the other custom nodes, this also have property called 'Define' which tells you which properties you have to define in code:

Please ignore the current_dialogues property!

Now the next screenshot will be of the code. To take reference, write $NPCNodeName

dialogues: The dialogues you want your NPC to say. Pretty self-explanatory. Please write dialogues like this:
["first_dialogue", "second_dialogue", "third_dialogue"]

satisfied_dialogues: NPC will speak when he will get what he wants. Please write dialogues in the way written above

AreaCollider: Give it the node path of the Area node which we added in as a child of NPC

Player: Give it the node path of the player

Player_Inventory: Give it the node path of Inventory node inside our PlayerCharacter3D

DialogueBox: Remmeber we added a node called 'DialogueBox', Give that node's path to this property

thing_needed: Remember when coding our Golden Apple, we gave it's ItemName property Golden Apple. So whichever InventoryItem3D you want your NPC to take, give that InventoryItem3D's ItemName to it, in my case it's golden apple. Write the name like this: "ItemNameHere"

Quantity: How many of that item this NPC wants. In our player, he will only have 1 golden apple so i wrote it 1

The last thing we have to do is to go to Project>Project Setting>Input Map and add a keybinding named 'next' and add whatever key you want to go to next dialogue

Now your player's no longer a introvert. You can collide with NPC to start conversation and to switch to next dialogue, press the key that you set in the keybind. Enjoy!!