Skip to main content

Encounter System

Encounters allow for creating easily-moddable randomized events, such as a walk in the woods that could lead to any number of events occurring. You could add a new encounter with a wandering merchant, or perhaps a new monster encounter, or a new quest.

The encounter system works the same way as the rumor system - refer to that document for details on weights and the optional check functions.

note

When adding custom encounters, do so in a Script asset that calls Encounter.Add. Make sure your Script asset loads after the Script_EncounterSystem and Script_EncounterList scripts from the Core module, so that the encounter system is actually loaded and the built-in encounter groups (listed below) are loaded. You can do this by clicking the Load Order button in the top right of the script editor, and configuring it accordingly.

Reference

Encounter.Add
group = ...
fn = ...
weight = ...
check = ...
  • group (string) - ID of the group to add the encounter to
  • fn (function) - activation function that should start the encounter
  • weight (number) - optional - relative selection weight; defaults to 1
  • check (function) - optional - eligibility check function; encounter is not selected if function returns false
Adds a new encounter to the group with the specified ID. Note that arguments are expected as named keys in a table. The encounter activation function (the fn parameter) should generally cause a switch to a different scene, so that some kind of interactive encounter can start.
This function is part of the Core module. (Hover for details)
Encounter.Roll
group
  • group (string) - ID of the group to get an encounter from
  • (function) - activation function of the selected encounter, or nil if there are no eligible encounters
Selects a random, eligible encounter from the specified group, and returns its activation function. Call the function to start the encounter.
This function is part of the Core module. (Hover for details)

Built-in encounter groups

These encounter groups are used by the Core module. If you want to add encounters to the main game's locations, simply use one of the variable names listed below as the value for the group argument to Encounter.Add.

Of course, you do not have to use one of these groups; you can also create a new one if you like.

Variable NameDescription
k_EncounterGroup_ForestForests east of North Finmer.