This is a short tutorial about how you can spawn an NPC.
Remember to SAVE as often as possible!
To spawn NPCs, you need a Community:
- In the Asset Browser right-click and choose: Create/Community.
- Give it a name, e.g npc_community.
- Double-click on your new file.
Next we will have to define NPCs, and what they do.
In the Asset Browser, look for an Entity Template citizen_poor in \templates\characters\appearances\crowd\citizen_poor
- Copy the Entity to your level folder and double-click on it:
- Click on the NPC from the left window. In the tab Node properties:
Note: you can also change NPC Behavior from its Entity Template (invulnerable, aggressive, etc.), in Node Properties, see below.
Under the tab Spawnset:
- Right-click under Comment (in the field with the blue line) and choose Add Element, repeat the task for every greyed-out field.
- Fields descriptions:
In the Asset Browser:
- There are predefined actions in templates/environment/actionpoints.
For example, to have a gossip animation look under the folder default and choose gossip.
- The gossip-JobTree shows a preview of the action, and its category (on the right of the Play button). Double-click on it and drag your NPC Entity into the right window, then right-click->Use selected entity. Clicking on the Play button will show the animation.
- Close the JobTree File. Note: if an error appears, click on cancel to avoid further error messages.
- Now, drag the gossip Entity on a new layer of the world, e.g actionpoints.
- Give it a tag, e.g walter_ap.
Under the tab Timetable:
- Right-click under Name (in the field with the blue line) and choose Add Element, repeat the task for every greyed-out field.
Now, a quest has to be written in order to activate this community, so that the NPC will get spawned.
In the Asset Browser:
- Right-click and Create/Quest, name it e.g myquest.
- Open the file and right-click in the right panel and Complexity management/Start, a red arrow will show up.
- Right-click and select Gameplay/Story Phase Setter.
- Link the Start arrow and the in part of the Story Phase Setter.
- Click on the Story Phase Setter and from the left window:
Now, a quest entity is needed in the world to start the quest.
In the Asset Browser:
- Right-click and Create/Entity Template.
- Name it myquest_entity and open it.
- In the upper right window, right-click and select Create ‘CQuestComponent’.
- Click on the new Node.
- In the Node properties tab at the bottom, link your quest with the field next to Quest.
Note: the Quest log field is for the journal file, see Quest Tutorial (basics).
- SAVE and close it.
Now drag this entity on a new layer of your world, e.g queststuff_layer. From there the NPC should work.
To change NPC behavior, open its Entity Template from the Asset Browser (make sure you've copied it to your level first!), click on the Node properties tab, then click on the NPC model on the left: the tab will get populated.
Having non-attackable NPCs can be useful depending on your design choices. You also might want to have it invulnerable to prevent possible odd behaviors.
To have non-attackable NPC:
- set isAttackableByPlayer to false
- set immortalityMode to AIM_Immortal.
Note: even with isAttackableByPlayer option disabled, standard NPCs will start fist-fighting when hit with magic. To work-around that, set attackReactionRange to 0 (default: 20).
You'll probably want to make an NPC walk from point A to point B from your Quest file e.g you want him to go somewhere after the end of a dialog. There are 2 ways to do it.
Note: if you want an NPC to go somewhere as a background action, just use Actionpoints with timetables.
- Using a Path:
1. Make sure you have Sprites turned on in View/Filters _debug options.
2. Create a Path in your level (Right-click/Navigation/Path). Tag it.
3. Go into Vertex Edit mode under the Tools tab.
4. Edit the shape of the path to your liking by moving/adding nodes (see Vertex Editor article).
5. In your quest, add a Script block. Select QMoveAlongPathinScene as the function.
6. Enter the NPC's tag, your path's tag and the MoveType (Walk/Run).
Note: you can also edit the Speed parameter.
7. Set UpThePath (sets the direction same as the Path arrow) and FromBeginning to True.
If you don't do that last step it seems the NPC just walks to the closest end of the path, from where he is.
- Using a Waypoint:
You can also just use QMoveToObject if you just need something simpler and then use a Waypoint instead of a Path.
Remember to SAVE as often as possible!
Table of contents
Prepare NPC spawning
Create a Community
To spawn NPCs, you need a Community:
- In the Asset Browser right-click and choose: Create/Community.
- Give it a name, e.g npc_community.
- Double-click on your new file.
Next we will have to define NPCs, and what they do.
Prepare a character
In the Asset Browser, look for an Entity Template citizen_poor in \templates\characters\appearances\crowd\citizen_poor
- Copy the Entity to your level folder and double-click on it:
- Under the Appearances tab, you can see the different appearances variants for the character. Find the one that you want to use, e.g citizen_poor_01.
- Under the Voicetag tab, on the first row (Voicetag = CITIZEN POOR FLOTSAM 01), choose in column Appearances citizen_poor_01.
- Click on the NPC from the left window. In the tab Node properties:
- Give him a tag, e.g walter – write it in the empty field next to tag/
- Give him a displayName, e.g Walter – Note: this seems to be buggy at times.
Note: you can also change NPC Behavior from its Entity Template (invulnerable, aggressive, etc.), in Node Properties, see below.
Populate the community
Under the tab Spawnset:
- Right-click under Comment (in the field with the blue line) and choose Add Element, repeat the task for every greyed-out field.
- Fields descriptions:
- Entity ID: it isn't mandatory to write something in there but it helps when there's a lot of NPCs. The ID can be walter for example.
- Entity Template: select the NPC template (walter) in the Asset Browser and click on the green arrow in this field to link it.
- Appearances: the NPC appearance, e.g citizen_poor_01.
- Story Phase Name: name of the story phase, this is useful when you want to reuse an NPC, somewhere else after a previous quest has been done. For the first time, just use default_phase.
- Timetable Name: name of the timetable (a table saying what the NPC does and when), e.g walter_tt.
Add actionpoints (APs) to the NPC
In the Asset Browser:
- There are predefined actions in templates/environment/actionpoints.
For example, to have a gossip animation look under the folder default and choose gossip.
- The gossip-JobTree shows a preview of the action, and its category (on the right of the Play button). Double-click on it and drag your NPC Entity into the right window, then right-click->Use selected entity. Clicking on the Play button will show the animation.
- Close the JobTree File. Note: if an error appears, click on cancel to avoid further error messages.
- Now, drag the gossip Entity on a new layer of the world, e.g actionpoints.
- Give it a tag, e.g walter_ap.
Set up the timetable
Under the tab Timetable:
- Right-click under Name (in the field with the blue line) and choose Add Element, repeat the task for every greyed-out field.
- Name: name of the NPC's timetable, for example walter_tt.
- Time: when NPC starts acting. This is important when the npc has to do different things at different times. Basic value: 00:00.
- Layer name: select the layer that contains the AP (under the Scene panel) and click on the green arrow to link it.
- Category: the category of the AP, for example default.
- AP-Tags: the tag of the AP, for example walter_ap.
Now, a quest has to be written in order to activate this community, so that the NPC will get spawned.
Link to a quest
In the Asset Browser:
- Right-click and Create/Quest, name it e.g myquest.
- Open the file and right-click in the right panel and Complexity management/Start, a red arrow will show up.
- Right-click and select Gameplay/Story Phase Setter.
- Link the Start arrow and the in part of the Story Phase Setter.
- Click on the Story Phase Setter and from the left window:
- Click on the + in the field next to Spawnsets.
- Click on the red arrow of the new field and choose CActivateStoryPhase.
- Click on the field next to the new Spawnset field and link your npc_community.
- In Phase, select your story phase, for example default_phase.
Now, a quest entity is needed in the world to start the quest.
Create a quest entity
In the Asset Browser:
- Right-click and Create/Entity Template.
- Name it myquest_entity and open it.
- In the upper right window, right-click and select Create ‘CQuestComponent’.
- Click on the new Node.
- In the Node properties tab at the bottom, link your quest with the field next to Quest.
Note: the Quest log field is for the journal file, see Quest Tutorial (basics).
- SAVE and close it.
Now drag this entity on a new layer of your world, e.g queststuff_layer. From there the NPC should work.
Change NPC behavior
To change NPC behavior, open its Entity Template from the Asset Browser (make sure you've copied it to your level first!), click on the Node properties tab, then click on the NPC model on the left: the tab will get populated.
Turn NPC to non-attackable/invulnerable
Having non-attackable NPCs can be useful depending on your design choices. You also might want to have it invulnerable to prevent possible odd behaviors.
To have non-attackable NPC:
- set isAttackableByPlayer to false
- set immortalityMode to AIM_Immortal.
Note: even with isAttackableByPlayer option disabled, standard NPCs will start fist-fighting when hit with magic. To work-around that, set attackReactionRange to 0 (default: 20).
Quest actions
Make an NPC walk
You'll probably want to make an NPC walk from point A to point B from your Quest file e.g you want him to go somewhere after the end of a dialog. There are 2 ways to do it.
Note: if you want an NPC to go somewhere as a background action, just use Actionpoints with timetables.
- Using a Path:
1. Make sure you have Sprites turned on in View/Filters _debug options.
2. Create a Path in your level (Right-click/Navigation/Path). Tag it.
3. Go into Vertex Edit mode under the Tools tab.
4. Edit the shape of the path to your liking by moving/adding nodes (see Vertex Editor article).
5. In your quest, add a Script block. Select QMoveAlongPathinScene as the function.
6. Enter the NPC's tag, your path's tag and the MoveType (Walk/Run).
Note: you can also edit the Speed parameter.
7. Set UpThePath (sets the direction same as the Path arrow) and FromBeginning to True.
If you don't do that last step it seems the NPC just walks to the closest end of the path, from where he is.
- Using a Waypoint:
You can also just use QMoveToObject if you just need something simpler and then use a Waypoint instead of a Path.