How do games implement their triggers and events that make up the plot of the story. For example, to be concrete how would one implement the story of a game such as The Legend of Zelda: A Link to the Past. I'm assuming there is some kind of scripting that somehow hooks into the game world state? I know absolutely nothing about scripting and game development. And have no clue how the underlying code would be architected in terms of classes, data structures, design patterns, etc.
In the simplest terms i can put it.
- There will be some kind of "trigger" volume in most cases. When the player steps into this volume it will trigger the "event".
- Volumes will be a cube, or a sphere, or some other 3D primitive.
- The script will either be a pre-animated cutscene, in which case an animation will be played, or the gameplay script will be some kind of finite state machine (FSM).
- Different "states" will be triggered upon in game events, such as retrieving an item, or beating a boss.
- The mission will be "over" when the final state is run, this will usually update the players profile to say that a particular mission has been complete. And most likely cause the next FSM to be loaded.
The FSM may be defined like
- Get Object A
- Get Object B
- Get Object C
- Play cutscene putting triforce together
- Boss defeated
- Play cutscene
- Load next "mission".
Each "state" within a FSM may contain its own FSM. All of this can be defined with data, and doesnt necessarily require its own scripting language.
I want to add some more information to what Matt already mentioned by explaining how the RPG Maker does specific story progression and states. Though one can implement a more complex system the simplified way how the RPG Maker does it should be a good start.
In maps we can find certain triggers or entities. That can be an invisible tile which executes some code when the player steps on it or just a NPC you can talk to. Each one has different properties and provides different ways to interact with. Assume we have a NPC who would send you give you a quest - the first time you talk to him he would say something different than later on. Using pages for entities one can write code for different situations which is only executed under certain conditions. The RPG Maker uses so called switches - just boolean variables which are either on or off. At the beginning of the game a switch
HasAcquiredQuestX might be
off and the NPCs page 1 (giving the player the quest and turning on
HasAcquiredQuestX) would be executed. Speaking to him now would maybe execute page 2 with some text like "Oh did you finish your quest yet?". Once you finish the quest another trigger might turn on a switch
HasFinishedQuestX which lets our aforementioned NPC execute page 3 which will reward you with glory, gold and items.
This is a very easy way to work with story progression, however the more content the game has the more switches you will have and at a certain point it is definitely better to consider using finite state machines!