A First Look, Part 2

From RPG Creation Kit
Jump to navigation Jump to search

We've left Part I of this Tutorial while being in Stage 20, with the Thief approaching and forcing us to dialogue with him, and we've seen that this happened because of the Thief's Behaviour.

We are at the highlight of the quest, from now on the next stage will be determined by the Player's actions. This reveals the fact that Quest Stages are not always to be executed in order, some of them can be skipped or ignored, and you are free to set and branch you quests as you want.

The conversation the Player will have with the Thief is the Current Dialogue the Thief has, and it is called "TheThiefOfTheDeadDefaultDialogue". To view it you can search it in the Rck Object Viewer or in the Rck AI Editor (Behaviour tab) while having "TheThiefOfTheDead001" selected.

Open it up in the Node Editor and let's take a look.

You should be able to get an idea on what happens, the Dialogue starts with the Entry Node that redirects to an NPC Dialogue Line, the NPC speaks its line and then the player is prompted to say something (After Line = Player Questions).

The quest branches from there, in base of what the player will pick the quest can end in three ways, as we've seen in the beginning of this article. We will analyze every possible outcome that will let the player complete the quest.

1. Stage 30 - Player Kills the Thief

The Player can decide to kill the Thief by selecting the dialogue option "[Attack] Your crimes are unforgivable". Find the option in the Dialogue, and let's analyze what happens next. The end of the question is connected to a NPC Dialogue Line Node, so the Thief will speak a line "This is not your grave, but you are welcome in it". What should happen next, is that the Thief will attack the player, and this is achived via Events in the configuration of the node. Click on "Show/Hide" to reveal the hidden properties and settings, then open the Events.

You will see that there is a Consequence of type "RckAI Add In Faction" which pretty much explains itself, it allows to set an NPC to a determined Faction. The Consequence is configured to Add the NPC with ID "ThiefOfTheDead001" to the Faction with ID "AgainstPlayer".

Setting an NPC to the "AgainstPlayer" Faction will make the NPC attack the Player at sight, which is exactly what we're looking for.

The Dialogue continues with a special Node, which is the Dialogue AI Invoke, this node allows you to call AI Functions from within the Dialogue, the AI that will be changed is obviously the AI that is talking to the Player. Just as we've changed the Behaviour the last time (going from DefaultBehaviour to FollowPlayer) here we are switching Behavior again, this time to the EmptyStatePurpose that will make the NPC standing still. We want him to stand still because as soon as he detects the Player, he switch in Combat and will attack him, because we've set him in the "AgainstPlayer" Faction.

The Dialogue ends with an End Node, which has two Quest Updaters that lets the Player complete the Stage 20 and set the Current Quest Stage to 30.

The Stage 30, if looked in the Quest Editor, doesn't have anything special but the description.

So what happens now is that the Current Quest Stage is 30, the Player has as the current objective "Kill the looter", and the Thief NPC is attacking the Player.

Perfect, now the last thing that we need is to update the quest when the Thief dies.

To do that, we utilize the Quest Script we've seen in the Quest Editor.

A Quest Script is very similiar to the Quest Stage Script we've seen and used before, but it has one big difference. A Quest Stage Script is designed to execute some lines of code and then get destroyed, while the Quest Script runs periodically while a quest is active.

That means that throughout the whole mission, and still right now, every X seconds the Quest Script assigned to this quest was being executed.

The Quest Scripts are useful in the occasion when you don't really know when something needs to happen, while with the case of the Quest Stage Scripts we always knew when something had to happen (we knew for example that the Thief had to spawn after speaking to Mother Nebivia).

So a Quest Script is perfect for our case, since we don't really know at which time the Player will kill the Thief, or if he will at all.

The script we're talking about is "EveryDeadMansNightmareQuestScript" and it is fundamentally very simple, altrough it is a little bit longer. If you've understood the previous Scripts, you shold have no problem getting this too, and once you got it, we're done.

Open the script and let's analyze it.

The first thing that you'll notice is that it utilizes four variables:

bool doonce = false;
bool doonce1 = false;
bool doonce2 = false;

RckAI thiefofthedead = null;

"doonce(1,2)" are booleans, they are used to ensure that some things only happen once, we will set those variables to true as soon as we execute the lines we want to be executed only once.

"thiefoftheidead" instead, is a reference to the NPC. It let us access to every aspect of the NPC, in our case we will use it to check if the NPC died.

Quest Scripts always have at least two functions:

public void Start()

And

public override void CustomUpdate()

Let's analyze both of them. The first one will allow you to set the value of the questScriptExecutionDelay, which is the X amount of seconds that have to pass for the "CustomUpdate" function to be executed. Not only, the Start calls the function "RunQuestScript()" that will make the script run.

public void Start()
{
     quest.questScriptExecutionDelay = 1f; // CustomUpdate runs every 1 second.
     RunQuestScript(); // Starts the CustomUpdate
}

Let's take a look at the CustomUpdate(): This may look a intimidating at first, but it's actually very simple as well. The first two lines:

if (thiefofthedead == null)
  CellInformation.TryToGetAI("ThiefOfTheDead001", out thiefofthedead);

Says: if the reference of the NPC is null, try to get it. The code will not go forward this point reference is found and set. The reference will be available to the Quest Script when the Thief NPC will be loaded in the scenes, at the next call of the CustomUpdate() the function "TryToGetAI" will finally get the reference. This is the standard way to get NPC references and it is used widely throughout the whole Demo.

The "else" block runs only if the reference is set, for now ignore the first and last block and focus at the one at the center:

else if(quest.currentQuestStage == 30 && !thiefofthedead.isAlive && !doonce1)
{
   // Progress with quest
   RCKFunctions.SetQuestStage(quest.questID, 40);
   RCKFunctions.CompleteQuestStage(quest.questID, 30);

   doonce1 = true;
}

The If condition states "If the Current Quest Stage" (of SQ_EveryDeadMansNightmare obviously) is equal to 30 and "thethiefofthedead" is NOT alive and "doonce1" is false, execute the block below (the "!" means NOT).

What the block below does? Exactly, it lets us continue with the quest. It sets as Current Quest Stage the Stage 40, it completes the Stage 30, and it sets the variable "doonce1" to true to ensure that it will only get executed once.

And that's it. That's this Quest Scripts is all about. We will analyze the other two blocks but you should see that they do pretty much the same thing as this one, but under different conditions.

Stage 40 - Completing the Quest.

Open the Quest again in the Quest Editor and take a look at Stage 40.

You will see that it has a Quest Stage Script assigned, and that the name of the script isn't tied specifically to this stage. This happens because what this script simply does is to change Mother Nebivia's Dialogue to another one, and this Dialogue needs to be set in both scenarios, if the Player Kills the looter or convinces him to run away, so it is common and reused in more than one stage.

You can open it and take a look, you may guess what happens, we try to take the reference of Mother Nebivia and change her dialogue to the Dialogue with ID "MotherNebivia001_EDNConclusion", but in the "else" block there is something that has to do with the Save System. That happens because at the time the Quest Stage runs, Mother Nebivia could NOT be loaded and NOT accessible via reference, so what we do is to modify directly the Save File by accessing the part where Mother Nebivia is saved, and we modify her settings from there. We've analyzed plenty of the RPG Creation Kit's functionalites for now, I don't want to go too deep on the Save System as it's not needed at this point. That general overview will do the job.

Most importantly, you can notice in the Quest Editor that this stage has the checkbox "Complete Quest", which means that as soon as this stage is completed, the Quest will be completed.

Anyway, thanks to the Quest Stage Script Mother Nebivia has now a new Dialogue, and its ID is "MotherNebivia001_EDNConclusion" open it with the Rck Object Viewer, and take a look. You should be able to understand what happens, at the beginning the Conditions Node checks if the Player completed Stage 30, which means if the Player killed the Thief (becase Stage 30 is only completed when the Thief dies), so we use it to determine which path the Player took. The dialogue flows without any special setting, and you can see that she will say different things in base of what the Player did.

Focus on the line "We don't have much...", this NPC Dialogue Line has as the "After Line" Player Questions, what the NPC asks to the Player is if he wants to take the reward, or leave it to the Curch. Both ends redirects to NPC Dialogue Lines but the one above that is said if the Player accepts the reward contains two Consequences.

Click on "Show/Hide" and open the Events, you will see that there are two consequences which adds 50 golds to the Player's Inventory and displays an Alert Message. Most importantly, there is a Quest Updater that completes the Stage 40, therefore, it completes the Quest.

While on the node at the bottom, the one that gets executed if the Player refuses to take the reward, there are no Consequences set, but a Quest Updater that will complete the Stage 50 (we'll get to that soon).

In both responses, the Dialogue gets redirected to a Change Dialogue node, that will change the Dialogue of the NPC who is currently talking to which dialogue you decide, in this case, it gets set back to Mother Nebivia Defaults dialogue.

The last thing that happens is that the End node gets executed, this will stop the dialogue but not before executing its Events and Result Script. The result script assigned is called "SQ_EveryDeadMan_SendThiefIntoOblivion", which has just one line of code that sends the Thief into the Oblivion, making him disappear from the world to be not seen ever again.


With that, we have completed the Quest and we have covered everything I wanted to cover for this first look, the remaining text will explain how the other two ways of ending the Quest works. Make sure to follow them, and get to the end of this article to draw the conclusions.

2. Stage 50 - Player Convinces the Thief

Let's rollback to the beginning of this Part 2. We're at Stage 20 and we are in the dialogue with the Thief. This time we will play the quest so that the Player convinces the Thief to stop doing what he's doing.

So open the "ThiefOfTheDeadDefaultDialogue" again. We select the options that persuade the Thief to go away:

"What are you doing here?" -> "These are not buried goods..." -> "[Persuade] Their Families renounced...". Look how the dialogue flows.

Things are really the same as the previous situation, but obviously the settings differ. After speaking 4 lines, the Dialogue is redirected to the Dialogue AI Invoke node, that we said will call the selected function on the NPC that is speaking. Show/Hide the Node to see that we use the same function to change the Behaviour of the Thief to "BTree_TheThiefOfTheDeadPackingStuffBehaviour", which will do nothing but allow the NPC to reach a position at the cementary and stand still there. We also call another Dialogue AI Invoke, that calls the function "SwitchBehaviourTree", this function will make the NPC immediatly execute the New Behaviour we've set in the previous node.

Then, we change the Dialogue of the Thief with the Change Dialogue node to a Plain Dialogue. notice that this node also has two Quest Updaters set, that will Set the Current Quest Stage to 50 and complete the Stage 20 as soon as the node gets executed.

The Dialogue is ends, the NPC will move to its destination target and wait there with its new dialogue set, that will simply say "I'll pack my stuff and leave".

The Stage 50 has been set as the Current Stage, let's look at it in the Quest Editor.

You'll notice that it's identical to the Stage 40,this one too has the checkmark on "Complete Quest" and this one too utilizes the same Quest Stage Script. The only thing that differs is the description.

So the Stage 50 gets set, and the Quest Stage Script is executed. We've analyzed the script before, and we know it simply sets a new dialogue to Mother Nebivia, the one with ID "MotherNebivia001_EDNConclusion". The Player will have to return to Mother Nebivia and speak to her. This time the Quest Stage 30 has not been completed, so the Conditions Nodes will always fail, resulting in Mother Nebivia saying an alternative version of the Dialogue, where she's not sad for the death of the Thief but happy for his redemption.

The last line the NPC speaks, completes the Quest Stage 50 and therefore the Quest.

3. Stage 60 - Player takes the bribe

The last outcome is the simplest.

Let's rollback one more time to the beginning of Part 2, We are at Stage 20 and we are in the dialogue with the Thief. This time we accept the Thief's bribe, open again the "ThiefOfTheDeadDefaultDialogue" and let's look at what happens if we select that option.

The NPC Dialogue Line Node has 3 Quest Updaters, one marks as completed the Stage 20 (and notice it displays the log), while the second one sets as the Current Quest Stage the Stage 60 (and hides the Log), and immediatly after setting it, the third Quest Updater completes the Stage 60 (and hides the Log too).

Open the Quest and take a look the Stage 60, the description is a comment and this tells us this is a silent stage, which is simply a stage that doesn't display its description to the player. It's important to notice that it also completes the quest, so by setting the Current Stage to 60 and Completing the Stage 60 with that NPC Dialogue Line, we will complete the Quest.

The Dialogue keeps going the same, change of Dialogue, change of Behaviour, this time the Dialogue will allow the Thief to say "You had what you wanted... get lost" while the Behaviour will allow the Thief to keep digging the grave by using the NPC Action Point.

The End Node has a Consequence that will add the 150 golds to the Player Inventory.

Conclusions

I know this has been quite a journey and that it wasn't a walk in the park. I could have illustarted you the most simple quest with few pharagraphs, but you wouldn't have really learned anything. This deep dive into this complex Quest illustrated the relationships between the elements of the RPG Creation Kit, how they are made, how they work and how they can interact and merge to form your quests and your game. You've already explored the most you'll need to know to start making your game.

I really think that having made this effort now is worth and that it will prove to be worth in the near future.

In the next articles, we will finally start creating new things instead of analyzing existing ones, and the pace will be slowed down, allowing you to properly absorb the informations.

This article should have given you a proper overview of the RPG Creation Kit, you should have understood the underlying principles of it, even if you still have questions or doubts about some things, don't worry. We'll hopefully get to them.


The Extra section below will give you some extra tips and will analyze some situations that occurs when the Player tries to get around the rails you set for the quest, and how to avoid bugging the quest if he does something he wasn't supposed to do.

As an exercise, I would suggest you to pick a quest in the Demo and try to reconstruct like we did here. You can start with the quest "A Donation of Wheat", which is the easiest quest the Demo has.

Extra - "And what if..."

When making and implementing quest stages, you should always ask yourself "and what if the player does this thing that he wasn't supposed to do?".

By the nature of the Open World RPG you can make with the RPG Creation Kit, the player has a lot of freedom that can go, sometimes, at your disadvantage.

For example, we've scripted the quest we've analyzed in this tutorial so that this happens:

"When the Player arrives, he will see the Thief digging a grave. When the player will get closer, the thief will stop digging and talk to the player. Here the player can decide what to do, the quest can end in three ways: [..]"

Right, that's a nice script - but what if the player attacks the Thief with a bow before he gets close enough to have the NPC trigger the change of Behaviour and start dialoguing with the Player?

Most of those situations can be resolved with the Quest Script, as it happens this case. The two blocks of code we ignored when we've analyzed the Quest Script of the Every Dead Man's Nightmare quest does exactly this.

The first one covers this case we've just told, while the second one covers another case:

What if the Player convinces the Thief to run away, but then kills him anyway?

Again, this is covered by the third block of the Quest Script.

Try to take a look at them and understand what is going on.


More in general, whenever you're designing Quests and making stages, always think "and what if the player does that?", see what happens and if it causes a bug or a behaviour it shouldn't be in the game, fix it.