Narrative Events

Narrative events are a method for easy packaging of a mission with some advice or narrative content, wrapped in an intervention. They are mainly intended for use in early-game missions, which commonly have to show a mission with some advice and occasionally a camera movement, but they can be used for other purposes.

Once created, a narrative event may be associated with a number of trigger events (and optional conditions) that determine when it should trigger. See the Trigger Conditions section for more information. Preconditions may be also be set which narrative event must pass before it can trigger - see Preconditions.

On-issued and on-mission-completed script events may be specified - see the Scripted Events and Callbacks section. These script events are triggered when the narrative event object triggers its mission/advice and when the mission is completed. The intention is that these may be used by client scripts to easily daisychain narrative events together, so that the completion or triggering of one leads to the triggering of another.

Once set up, the listeners associated with a narrative event must be started with narrative_event:start.

By default, narrative events will attempt to reduce the intrusiveness of advice, including not delivering the advice at all, if it's detected that the advice has been delivered before. This typically occurs when the player is experiencing the same narrative event on subsequent campaign playthroughs. See the Narrative Event Categories section for more information.

Narrative events may be declared and supported in multiplayer mode, but their content delivery will not be wrapped in an intervention and no advice will be shown.

Loaded in Campaign loaded in campaign
Back to top

Creation

Narrative events create persistent mission_manager objects internally. Due to this, narrative events need to be created before the first tick occurs - see the section in the mission manager documentation on Persistence for more information.

narrative_event:new(
  
string name,
  string
faction key,
  [string
advice key],
  [table
infotext],
  [string
mission key],
  [string
completion event]
)

Creates and returns a narrative event object. An advice key, infotext, and mission key may optionally be specified. Alternatively, narrative elements (e.g. cutscenes, event messages) can be triggered by adding them as an on-trigger callback using narrative_event:set_trigger_callback.

Parameters:

1

string

Unique name amongst narrative event objects.

2

string

Faction to issue the content to.

3

string

optional, default value=nil

Advice key to play with content, from the advice_threads table.

4

table

optional, default value=nil

Infotext to issue with advice. This should be a table of strings, each specifying a record from the advice_info_texts table.

5

string

optional, default value=nil

Key of mission record from missions table to issue.

6

string

optional, default value=nil

Script event to trigger when the supplied mission is completed.

Returns:

  1. narrative_event narrative event

defined in ../working_data/script/_lib/lib_campaign_narrative_events.lua, line 91

Back to top

Usage

A narrative event object is created and returned by calling narrative_event:new. Once created, functions on a narrative_event may be called in the form showed below.

Example - Specification:

<narrative_event_object>:<function_name>(<args>)

Example - Creation and Usage:

local ne_example = narrative_event:new(name, faction_key, advice_key, infotext, mission_key, event_on_mission_completed)
    "example_early_game_narrative_event",
    "troy_main_dan_mycenae",
    "troy_camp_early_game_example_01",
    nil,
    "troy_main_mycenae_early_game_example_mission_key_01"
    "ScriptEventMycenaeExampleMission01Completed"
)

-- calling a function on the object once created
ne_example:add_trigger_condition(
    "FactionTurnStart",
    function(context)
        return context:faction():name() == "troy_main_dan_mycenae" and cm:turn_number() >= 3
    end
);

-- start listening for the trigger condition
ne_example:start();
Back to top

Querying

narrative_event:is_running()

Returns whether this narrative event is currently active and listening for its various trigger conditions. This becomes true when narrative_event:start is called and false when the narrative event triggers.

Returns:

  1. boolean is running

defined in ../working_data/script/_lib/lib_campaign_narrative_events.lua, line 249

narrative_event:has_triggered_this_campaign()

Returns whether this narrative event has triggered in this campaign save.

Returns:

  1. boolean has triggered

defined in ../working_data/script/_lib/lib_campaign_narrative_events.lua, line 257

narrative_event:has_been_seen_in_advice_history()

Returns whether this narrative event has ever been triggered in any campaign, from the advice history. This is mainly for internal use but can be called externally if required.

Returns:

  1. boolean has triggered in

defined in ../working_data/script/_lib/lib_campaign_narrative_events.lua, line 265

Back to top

Scripted Objectives

If a mission key was specified in narrative_event:new then this mission type can be customised using the functions in this section. These call the equivalent functions on the internally-created mission manager. Alternatively, the internal mission manager may be directly accessed with narrative_event:get_mission_manager, at which point function calls may be made to it to customise the mission to be delivered.

If no mission key was specified to narrative_event:new then no mision manager will have been generated, and these functions will produce errors and return false.

narrative_event:add_new_objective(string objective type)

Adds a new scripted objective to the internally-created mission manager. See mission_manager:add_new_objective for more information.

Parameters:

1

string

objective type

Returns:

  1. nil

defined in ../working_data/script/_lib/lib_campaign_narrative_events.lua, line 297

narrative_event:add_condition(string condition)

Adds a new condition to the mission objective most recently added with narrative_event:add_new_objective. See mission_manager:add_condition for more information.

Parameters:

1

string

condition

Returns:

  1. nil

defined in ../working_data/script/_lib/lib_campaign_narrative_events.lua, line 310

narrative_event:add_payload(string payload)

Adds a new payload to the mission objective most recently added with narrative_event:add_new_objective. See mission_manager:add_payload for more information.

Parameters:

1

string

payload

Returns:

  1. nil

defined in ../working_data/script/_lib/lib_campaign_narrative_events.lua, line 323

narrative_event:set_mission_issuer(string issuer)

Sets a mission issuer for the internally-generated mission manager. See mission_manager:set_mission_issuer for more information.

Parameters:

1

string

issuer

Returns:

  1. nil

defined in ../working_data/script/_lib/lib_campaign_narrative_events.lua, line 336

narrative_event:get_mission_manager()

Returns the internally-created mission manager, which can be used to further customise the mission to be generated.

Returns:

  1. mission_manager mission manager

defined in ../working_data/script/_lib/lib_campaign_narrative_events.lua, line 349

Back to top

Payload Inheritance

Narrative events may be set to inherit mission reward payloads from other narrative events, if that other narrative event has not yet triggered by the time the first does. This is to allow chains of narrative missions set up where individual missions can be bypassed without the player losing out on the reward that mission would bring.

Consider two narrative events that encapsulates missions, one to recruit an agent and another to use an agent against an enemy target. Neither has yet triggered. The agent-action mission, which triggers when an agent is recruited, would naturally lead on from the first, but not in all cases - the player may be gifted an agent from an incident or other scripted event. By setting the agent-action mission to inherit the rewards of the recruit-agent mission, the rewards of the now-redundant recruit-agent mission will be rolled in to the agent-action mission, meaning the player is not penalised for having inadvertantly skipped a mission before it can trigger.

If the narrative event being inherited from has already triggered then those rewards are not inherited. Should one narrative event inherit the rewards of another, that second narrative event will shut down and be unable to trigger.

narrative_event:add_narrative_event_payload_inheritance(string narrative event name, string faction key)

Marks this narrative event as inheriting from another narrative event. The other narrative event is specified by the unique name and faction key supplied on creation.

Parameters:

1

string

narrative event name

2

string

faction key

Returns:

  1. nil

defined in ../working_data/script/_lib/lib_campaign_narrative_events.lua, line 373

Back to top

Scripted Events and Callbacks

narrative_event:set_event_on_triggered(string event)

Sets a script event that fires when this narrative event triggers. Other scripts can listen for this event and respond accordingly.

Parameters:

1

string

event

Returns:

  1. nil

defined in ../working_data/script/_lib/lib_campaign_narrative_events.lua, line 448

narrative_event:set_event_on_mission_completed(string event)

Sets a script event that fires when the mission associated with this event is completed, either successfully or unsuccessfully. Other scripts can listen for this event and respond accordingly.

Parameters:

1

string

event

Returns:

  1. nil

defined in ../working_data/script/_lib/lib_campaign_narrative_events.lua, line 461

narrative_event:set_trigger_callback(function callback)

Sets a callback to be called when this narrative event is triggered.

Parameters:

1

function

callback

Returns:

  1. nil

defined in ../working_data/script/_lib/lib_campaign_narrative_events.lua, line 474

Back to top

Narrative Event Categories

Narrative events will not show advice, or not scroll the camera despite a scroll target being set with narrative_event:set_camera_scroll_target_callback, if they reason that the player has seen the content enough times before. They do this to avoid irritating the player with too much advice and too many intrusive camera movements for content that they're familiar with. The category of a scripted event and the advice level (high/low/minimal) set by the player is used to make this judgement and determine whether:

  1. Advice should be played and the camera scrolled.
  2. Advice should be played with no camera movement.
  3. No advice or camera movement should be played.

In all cases the mission associated with the narrative event is triggered, if one was set up.

ValueDescription
NARRATIVE_EVENT_CATEGORY_ADVICE_MANDATORYSets that the advice associated with this narrative event is mandatory and will always be played, including camera movements, even if the advice level is set to minimal. Only in multiplayer mode or if an advice precondition fails will the advice not be shown in this case. Use this setting sparingly.
NARRATIVE_EVENT_CATEGORY_ADVICE_HIGH_PRIORITYSets that the advice associated with this narrative event is high-priority. The only circumstance in which a narrative event of this category would not show its advice would be if the advice level was set to minimal.
NARRATIVE_EVENT_CATEGORY_ADVICE_SPECIFIC_TO_FACTIONSets that the advice is normal priority, but that the advice shown is specific to the faction currently being played and not associated with the same narrative event but for different factions.
NARRATIVE_EVENT_CATEGORY_ADVICE_SHAREDSets that the advice is normal priority and is shared amongst many different factions for which this narrative event triggers (e.g. a particular early game mission shared between many different playable factions).

The values listed in the table above are defined in script as constants. The default narrative event category is NARRATIVE_EVENT_CATEGORY_ADVICE_SHARED.

narrative_event:set_category(number category enum)

Sets the category of the narrative event. Supply a constant value from the table above.

Parameters:

1

number

category enum

Returns:

  1. nil

Example:

ne_example:set_category(NARRATIVE_EVENT_CATEGORY_ADVICE_SPECIFIC_TO_FACTION)

defined in ../working_data/script/_lib/lib_campaign_narrative_events.lua, line 508

Back to top

Camera Scrolling

A scroll-camera target may be set with narrative_event:set_camera_scroll_target_callback. This specifies a target region, character or position to which the camera is scrolled when the mission and advice are shown.

If the narrative event has been seen before in the advice history, it may decide not to scroll the camera even when a scroll-camera target has been set. See the Narrative Event Categories section for more information.

narrative_event:set_camera_scroll_target_callback(function callback)

Sets a camera scroll target callback. This function will be stored and then later called when the narrative event is triggered. It should return a string specifying a region key (the camera will scroll to the settlement in the region), a number that specifies a character by command-queue index, or a table containing two numbers specifying a display position.

Parameters:

1

function

callback

Returns:

  1. nil

defined in ../working_data/script/_lib/lib_campaign_narrative_events.lua, line 545

Back to top

Preconditions

Precondition checks may be added to a narrative event that it has to pass in order to trigger successfully. Once added, each precondition is checked when the narrative event is started and also when the narrative event attempts to trigger.

Preconditions can be added with a name, which allows them to removed again if configuration is handled by multiple separate scripts that set a default behaviour for a particular narrative event and then customise that default.

narrative_event:add_precondition(function precondition, [string name])

Adds a precondition function.

Parameters:

1

function

Precondition function. This should be a function that returns a boolean value. Should the value evaluate to false when the precondition is called, the precondition is failed.

2

string

optional, default value=nil

Name by which this precondition function may later be removed with narrative_event:remove_precondition.

Returns:

  1. nil

defined in ../working_data/script/_lib/lib_campaign_narrative_events.lua, line 571

narrative_event:remove_precondition(string name)

Removes a previously-added precondition by name.

Parameters:

1

string

Name of precondition to remove.

Returns:

  1. nil

defined in ../working_data/script/_lib/lib_campaign_narrative_events.lua, line 612

Back to top

Advice Preconditions

Advice precondition checks may be added to suppress the advice registered to the narrative event under certain conditions. Should an advice precondition fail when the narrative event is triggered, the advice will not be shown. The narrative event and its associated mission will still trigger, however.

narrative_event:add_advice_precondition(function precondition, [string name])

Adds an advice precondition function.

Parameters:

1

function

Advice precondition function. This should be a function that returns a boolean value. Should the value evaluate to false when the precondition is called, the precondition is failed.

2

string

optional, default value=nil

Name for this advice precondition, by which it may be later removed with narrative_event:remove_advice_precondition.

Returns:

  1. nil

defined in ../working_data/script/_lib/lib_campaign_narrative_events.lua, line 651

narrative_event:remove_advice_precondition(string name)

Removes a previously-added advice precondition by name.

Parameters:

1

string

name

Returns:

  1. nil

defined in ../working_data/script/_lib/lib_campaign_narrative_events.lua, line 692

Back to top

Trigger Conditions

Trigger conditions must be added to a narrative event to allow it to trigger. One or more trigger conditions may be added with narrative_event:add_trigger_condition.

If no trigger conditions are added to a narrative event the only way it can trigger is by specifying it must trigger immediately when calling narrative_event:start.

narrative_event:add_trigger_condition(string event, [function condition], [string name])

Adds a trigger event and condition. If the narrative event has been started and the supplied script event is received and the optional condition passes, and no preconditions fail, then the narrative event will attempt to trigger.

Parameters:

1

string

Event name.

2

function

optional, default value=true

Conditional check to perform when the supplied event is received. If this returns true then the check passes. Alternatively, true (the default value) may be specified to always pass when the event is received.

3

string

optional, default value=nil

Name for this trigger listener. If specified, the trigger listener may be later removed during configuration by narrative_event:remove_trigger_condition.

Returns:

  1. nil

defined in ../working_data/script/_lib/lib_campaign_narrative_events.lua, line 731

narrative_event:remove_trigger_condition()

Removes a previously-added trigger condition by name.

Returns:

  1. nil

defined in ../working_data/script/_lib/lib_campaign_narrative_events.lua, line 787

Back to top

Starting

narrative_event:start([boolean trigger immediately])

Starts the narrative event listeners. If the narrative event has already triggered this campaign, or if its payload has already been inherited, then the listeners will not be started.
If the optional flag is set, the narrative event will attempt to trigger immediately on startup.

Parameters:

1

boolean

optional, default value=false

trigger immediately

Returns:

  1. nil

defined in ../working_data/script/_lib/lib_campaign_narrative_events.lua, line 812

Last updated 25/08/2021 12:07:49