“Welcome to our village.” “Welcome to our village.” “Welcome to our village.” “Welcome to our village.” Sometimes hearing an NPC say the same thing over and over can be boring. For players who are looking for some world-building or little lore bits, these one-phrase NPCs can be disappointing and cause them to even ignore all but the important NPCs. If you’ve spent hours creating these characters from nothing then you want your players to spend some time with them. That’s where adding in some extra dialogue can help. Instead of having an NPC say just one thing repeatedly, let’s look at a few ways to improve their comments.
One simple way to have an NPC say something different each time the player interacts with them is to use self-switches. After the message, just turn on a self-switch to change the event page and you can keep the NPC from saying the same thing over and over.
Page 3 looks remarkably similar, though self-switch B is the condition instead
All it takes is three event pages, and you can make an NPC feel more alive.
Unfortunately, self-switches are limited so you can only have a few different comments before ending up stuck on the last page. So let’s look at another option.
Unlike self-switches, variables don’t have a limit. Using a variable to keep track of how many times you’ve spoken to an NPC means the only limit to their comments is your imagination. We’ll use conditional branches instead of event pages in this example to keep all the NPC’s messages neatly on one page. First thing is to make a variable that we will tie to this event, in this case it will be variable 6 (succinctly named “Boy’s count for speaking” because the more descriptive your variable the more likely you’ll remember what it’s for later on). Each time the player talks to this NPC we want the variable to increase by one, so we’ll have the variable change at the end of this page. But before we change that variable, we want the NPC to say what he’s supposed to.
We are using conditional branches to check what variable 6 currently is and have them play the right message. Since the variable changes at the end of the page, our first conditional branch checks if the variable is a zero and goes up by one from there. In this event we only have four conditional branches but if you want a chatterbox for an NPC you can have as many as you want.
Now the player and NPC can have as many conversations as you want, and they’ll happen in order. Have the player learn the life story of an old retired hero or, like in this example, reward the player for repeatedly talking to someone.
However, if you’re familiar with previous RPG Makers then you may have noticed an issue with the event page. Once the player has spoken to the NPC four times, he won’t say anything else since variable 6’s amount will be higher than any of the conditional branches. We could change the last one to check if it’s equal to or higher than 3, but then the player would get a new Dragon Blade each time. Instead, let’s add a second page to the event with the condition that variable 6 needs to be 4 or more. Now after the player has received the Dragon Blade any future interactions will just be page 2’s message.
Now we have the ability to create NPCs that can say more than one thing and even keep track of how many times the player has talked to them. But what if we just want the NPC to say something randomly?
We’ll be using variables again, though this time the variable is only here to pick a random number and not to keep track of how many times the player has interacted with the event. The first thing to do is set the variable to a random number, depending on how many possible comments we want. For this example, the old man has three things he could say so we’ll have the variable pick a number between 1 and 3. Once that’s set, we can use conditional branches like early to separate the different messages and we’re ready to go!
Now our old man event is happy to make a random comment whenever the player tries to talk to them. That’s more than enough for most NPCs that don’t have much to add to your main story, and gives you an easy way to slide some world-building into the game without forcing it all on your players at once. Sure, there’s the chance that the variable amount chosen will be the same as the last time the player interacted with the event, but it’s not a deal-breaker for most players.
But sometimes you just feel like going above and beyond when it comes to random dialogue. And one of the ways to do that is to use variable arrays and script calls.
If you’re not familiar with arrays, let me explain them as simply as I can. First thing to keep in mind is that variables can hold more than just numbers, they can even hold full sentences if you put those in quotation marks (“this” will work in a variable, this will not) so that MZ knows you’re not trying to do any fancy equations. Arrays let you make a list contained in a single variable, you just need to put them in square brackets and separate each item with a comma. If you put the following into the script section of a variable:
["Number 1", "Number 2", "Number 3", "etc."]
Then you’ll end up calling that list if you use the variable control character in a message.
For this example, let’s have the girl NPC have 3 different possible comments. In this situation we’ll have her event’s first page run automatically (using the autorun trigger) to set her variable and then a self-switch to turn her to page 2 where she’ll properly interact with the player. Another option is to set the dialogue variables at the start of your game, but since our example is just for one event and not a part of a full game that method isn’t necessary.
Page 2 is where the magic happens. The script call at the start picks a phrase, puts it into the variable that will be called with the message control character, and then removes that phrase from the event’s variable array. Once that’s taken care of, the rest of the event is straightforward: the message box where the phrase is actually said to the player and a conditional branch that checks to see if the event’s variable array is empty using a script call. If the array is empty, then in this example the self-switch is turned off so that page 1 will run again and fill the array with the phrases again.
The script call may look confusing, but it’s actually rather simple. All of the lines that start with “//” are comments that don’t do anything and are just there so that we know what each part is doing. If we remove them, then there are only three lines to explain (as a bonus, these lines are JavaScript which means they also work in MV).
words = Math.randomInt($gameVariables.value(5).length);
This looks at variable 5 and chooses a random number based on how many items are in the array. It starts at 0, so for our three phrases it is picking a number from 0 to 2.
$gameVariables.setValue(2, $gameVariables.value(5)[words]);
This sets variable 2 as the chosen item from variable 5, so that we can call variable 2 in the message later. $gameVariables.value(n)[#] is how we pick a single item from an array, but since we can’t use that script call in the message control character we need to set it to a different variable.
$gameVariables.value(5).splice(words, 1);
Splice here is a useful JavaScript function that lets us remove the chosen array item from variable 5. It does have more uses, but for this we’ll just focus on the fact it lets us remove one thing without having to touch the rest of the array.
What this all means is now our NPC will randomly say something, without repeating the dialogue until she’s gone through them all.
All of these methods have a place in games, so which ones you choose to use in your game depend on just what you want to do with your NPCs. Adding in a little extra NPC dialogue can really help bring your game’s world to life for the player, so have fun giving some of your NPCs some more messages. Now that you’ve learned these methods, what other ways could you add some randomness to your NPC’s dialogue?