RPG Event System

Hi,

I’m curious about how one would go about making an RPG event system, much like the one used in the game engine “RPG Maker”.

You can make different events on each tile in the game, that can do so many different things. You can move your event around, make it start a conversation ones interacted with, have it give items to the player and so on… all of which is fairly straight forward on it’s own, but when you start adding them together it gets unclear to me how you would avoid the need to make a new class for each and every event (which would end in a massive amount of classes).

I’ll give an example:

You have an NPC that ones talked to will check if you have met a certain criteria, checking your inventory for an item for example, if you have said item it will say one thing, if not another… further more it will teleport the player to a location if said criteria is met, granted the player answer yes on a popup window.

Sounds fairly simple to program, and as a standalone class it is no problem, but how do you make a system for this, so that the next npc that will do something similar can use the same class setup?

Or better yet, what if another NPC is only going to say some random word, but not give any items?

In a game like this, there is so many things you want your events to do, and you will have thousands of events, so making one class for each event seems like the wrong way to go.

I was thinking maybe some sort of editor that allows you to add a conversation line, a movement route, a teleport, a item, etc, so you can set up a list of “actions” to perform.

Anyone know how I could start doing something like this? :slight_smile:

Best Regards,
Winsj

You’ll need a bunch of classes for the generic event types. But, then you can create a data file (database, csv, or something similar) with the pieces that are different. In you example, you would have a data file that generally describes the pieces that must be glued together, then create a generic class to do those things.

Simplified example is a teleport trigger. You’d have a data file like [“trigger”:“greenportal”,“destination”:“town”],[“trigger”:“bluedoor”,“destination”:“wilderness”] then you would only need one event TeleportTriggerEvent that loops through each data entry, finds the trigger object, finds the destination object, then when player hits trigger object, move them to destination object.

This concept can be expanded to mix things together like npcInteractionEvent with a more complex data file that has something nested like [“npc”:“townbaker”,“options”:[“gotocellar”:“teleportcellar”,“goodbye”:“saygoodbye”]] where when the player gets within trigger radius of the town baker, the interaction event begins an interaction. When the player is presented with two options, if they choose gotocellar option, then it’ll kick off the TeleportTriggerEvent to teleport the player to the cellar.

You’re right, it’s a massive amount of code, but, no you shouldn’t write a separate class for each and every event.

Hi,

I have no real experience in designing such a system, but here are my thoughts.
I would suggest making a parent class for your events with all variables that can be used in your events and then make specific subclasses. And then maybe the handler which takes the event as input and applies the effects of the event.

I don’t see how you would get around creating single classes for individual events. You could make classes that can be used for multiple (similar) event types and then make subclasses of them for more detailed events. Maybe you could make the events as modular and reusable as possible. For example an event that is only responsible for open the popup window and has one other event assigned that is activated if your click on the option “Yes” and another event that is activated if you click on the option “No” in the popup window.

After you have designed and implemented the event system, you could write some sort of Editor interface where you can click on a tile in the world space, assign events and modify their values to make your workflow faster.

Generally I would separate the conversation system and the event system. Events may occur when you move on a certain tile in your world. You could make some sort of multidimensional array or dictionary, where you first store the x-tile and y-tile as key and then maybe a list of events to execute as value. You could assign unique IDs to event instances and if an event happened, store the id in a list (PastEvents). If the event is already in the list, do not activate it. Alternatively, you could simply remove the event from your general event dictionary/multidimensional array after it occured.

For the converation system, you could make a class (let’s call it ConversationSegment) that has a text variable, which will be displayed as the conversation part. Then you make a list of choices for the text. This choices will be presented as selectable texts if the player has reached the end of the text of the ConversationSegment. Each choice is associated with a condition class (conditions have to be fulfilled in order for the player to make the choice visible/possible during the gameplay), associated with one or more events and can be pointing to another ConversationSegment. This way you can make a treelike structure for each conversation. The conversation ends when you make a choice that does not point to another ConversationSegment or for regular NPCs without interactions, you simply make a ConversationSegment without any choices.

But there are already such systems in the asset store, maybe you take a look.