Narrative Events
For an overview of the narrative events system see the narrative
topic page.
Narrative events package a mission with some advice or narrative content, wrapped in an intervention
. They are designed to aid the creation of early-game missions, which commonly have to show a mission with some advice and occasionally a camera movement. They can also be used as a container to deliver other content like cutscenes, fullscreen movies etc.
Once created, a narrative event may be associated with one or more a number of trigger messages that determine when it should trigger. See the Trigger Conditions
section for more information. Preconditions may be also be set which the narrative event must pass before it can trigger - see Preconditions
. Preconditions can fire script messages when they fail.
On-issued and on-mission-completed script messages may be specified - see the Scripted Messages
section. Script messages may be triggered when a) the narrative event object triggers its mission/advice and b) when the mission is completed. The intention is that these may be listened for by other narrative objects, 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.
Narrative events output diagnostic information on the Lua - Narrative
console spool.
Loaded in Campaign | |
Loaded in Battle | |
Loaded in Frontend |
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(
name
string
,
faction key
string
,
advice key
[string
],
infotext
[table
],
mission key
[string
],
completion message
[string
],
suppress completion event
[boolean
]
) -
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
Unique name amongst narrative event objects.
2
Key of faction, from the
factions
database table, to issue the content to.3
optional, default value=nil
Advice key to play with content, from the
advice_threads
table.4
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
optional, default value=nil
Key of mission record from
missions
table to issue.6
optional, default value=nil
Script message to trigger when the supplied mission is completed. This can also be a
table
of strings if multiple completion messages are desired.7
optional, default value=false
Suppress mission completion event messages when this mission completes. This is experimental functionality.
Returns:
narrative eventnarrative_event
defined in ../../warhammer/working_data/script/_lib/lib_campaign_narrative_events.lua, line 132
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:
-- name, faction_key, advice_key, infotext, mission_key, messages_on_mission_completed
local ne_example = narrative_event:new(
"example_early_game_narrative_event",
"wh3_main_ksl_the_ice_court",
"wh3_main_camp_early_game_example_01",
nil,
"wh3_main_ksl_early_game_example_mission_key_01"
"KislevExampleMission01Completed"
)
-- calling a function on the object once created
ne_example:add_trigger_condition(
"FactionTurnStart",
function(context)
return context:faction():name() == "wh3_main_ksl_the_ice_court" and cm:turn_number() >= 3
end
)
-- start listening for the trigger condition
ne_example:start()
-
narrative_event:is_running()
-
Returns whether this narrative event is currently active and listening for its various trigger conditions. This becomes
true
whennarrative_event:start
is called andfalse
when the narrative event triggers.Returns:
is runningboolean
defined in ../../warhammer/working_data/script/_lib/lib_campaign_narrative_events.lua, line 322
-
narrative_event:has_triggered_this_campaign()
-
Returns whether this narrative event has triggered in this campaign save.
Returns:
has triggeredboolean
defined in ../../warhammer/working_data/script/_lib/lib_campaign_narrative_events.lua, line 330
-
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:
has triggered inboolean
defined in ../../warhammer/working_data/script/_lib/lib_campaign_narrative_events.lua, line 338
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(
objective typestring
)
-
Adds a new scripted objective to the internally-created mission manager. See
mission_manager:add_new_objective
for more information.Parameters:
1
objective type
Returns:
nil
defined in ../../warhammer/working_data/script/_lib/lib_campaign_narrative_events.lua, line 374
-
narrative_event:add_condition(
conditionstring
)
-
Adds a new condition to the mission objective most recently added with
narrative_event:add_new_objective
. Seemission_manager:add_condition
for more information.Parameters:
1
condition
Returns:
nil
defined in ../../warhammer/working_data/script/_lib/lib_campaign_narrative_events.lua, line 387
-
narrative_event:add_payload(
payloadstring
)
-
Adds a new payload to the mission objective most recently added with
narrative_event:add_new_objective
. Seemission_manager:add_payload
for more information.Parameters:
1
payload
Returns:
nil
defined in ../../warhammer/working_data/script/_lib/lib_campaign_narrative_events.lua, line 400
-
narrative_event:set_mission_issuer(
issuerstring
)
-
Sets a mission issuer for the internally-generated mission manager. See
mission_manager:set_mission_issuer
for more information.Parameters:
1
issuer
Returns:
nil
defined in ../../warhammer/working_data/script/_lib/lib_campaign_narrative_events.lua, line 413
-
narrative_event:get_mission_manager()
-
Returns the internally-created mission manager, which can be used to further customise the mission to be generated.
Returns:
mission managermission_manager
defined in ../../warhammer/working_data/script/_lib/lib_campaign_narrative_events.lua, line 432
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 encapsulate 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(
narrative event namestring
,
faction keystring
)
-
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
narrative event name
2
faction key
Returns:
nil
defined in ../../warhammer/working_data/script/_lib/lib_campaign_narrative_events.lua, line 456
-
narrative_event:add_message_on_issued(
messagestring
)
-
Adds a script message that is triggered when this narrative event begins to issue. Multiple messages to be triggered can be added by calling this function multiple times. If the narrative event wraps its contents within an
intervention
then this intervention will have started by the time these messages are triggered. This means that other scripts can respond to these messages and trigger their own interventions, which will queue up behind the intervention currently playing.Parameters:
1
message
Returns:
nil
defined in ../../warhammer/working_data/script/_lib/lib_campaign_narrative_events.lua, line 535
-
narrative_event:add_message_on_mission_completed(
messagestring
)
-
Adds a script message that fires when the mission associated with this narrative event is completed, either successfully or unsuccessfully. Multiple messages to be triggered can be added by calling this function multiple times. Other scripts can listen for this message and respond accordingly.
If no mission is associated with this narrative event then this setting will have no effect.Parameters:
1
message
Returns:
nil
defined in ../../warhammer/working_data/script/_lib/lib_campaign_narrative_events.lua, line 547
-
narrative_event:set_trigger_callback(
callbackfunction
)
-
Adds a callback to be called when this narrative event is triggered. This can be used to trigger narrative event actions like a cutscene or a fullscreen movie if a mission is not being triggered, or can be used to trigger actions in addition to a mission.
Parameters:
1
callback
Returns:
nil
defined in ../../warhammer/working_data/script/_lib/lib_campaign_narrative_events.lua, line 571
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:
- Advice should be played and the camera scrolled.
- Advice should be played with no camera movement.
- 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.
Value | Description |
---|---|
NARRATIVE_EVENT_CATEGORY_ADVICE_MANDATORY | Sets 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_PRIORITY | Sets 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_FACTION | Sets 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_SHARED | Sets 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(
category enumnumber
)
-
Sets the category of the narrative event. Supply a constant value from the table above.
Parameters:
1
category enum
Returns:
nil
Example:
ne_example:set_category(NARRATIVE_EVENT_CATEGORY_ADVICE_SPECIFIC_TO_FACTION)
defined in ../../warhammer/working_data/script/_lib/lib_campaign_narrative_events.lua, line 604
Should the narrative event trigger with an intervention
, the priority for that intervention will determine the sort order of interventions that want to trigger at that same time. The priority for each narrative event intervention is determined from the category (see Narrative Event Categories
), with mandatory and high-priority narrative events triggering before narrative events set with other categories. Alternatively, the priority may be overridden directly with narrative_event:set_priority
.
-
narrative_event:set_priority(
prioritynumber
)
-
Sets the priority for the
intervention
created by this narrative event, if one is created. If a priority is not set with this function then one is determined from the category (seenarrative_event:set_category
).
The supplied value should be a number between 0 (high priority) and 100 (lowest). See theintervention
documentation for more details.Parameters:
1
priority
Returns:
nil
defined in ../../warhammer/working_data/script/_lib/lib_campaign_narrative_events.lua, line 640
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(
callbackfunction
)
-
Sets a camera scroll target callback. This function will be stored and then later called when the narrative event is triggered. It should return either a
string
, anumber
or atable
that specifies a scroll target for the narrative event. Note that the narrative event may decide not to scroll the camera in any case due to advice settings, in which case this function would not be called - see the documentation forNarrative Event Categories
for more information.
If the function returns astring
, a region is looked up with this key and, if found, the region's settlement is used as the camera scroll target. If no region is found then a faction is looked up with the key. If found, the closest military force from the faction to the camera is used for the scroll target.
If the function returns anumber
then it is assumed to be a character command queue index value. The character looked up by this cqi is used as the camera scroll target.
The function may also return an indexedtable
that specifies a display position e.g.{100, 200}
.
If the function returnsnil
or any of the above queries fail then no scroll target is set.Parameters:
1
callback
Returns:
nil
defined in ../../warhammer/working_data/script/_lib/lib_campaign_narrative_events.lua, line 671
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(
preconditionfunction
, [
namestring
], [
fail messagestring
])
-
Adds a precondition function.
Parameters:
1
Precondition function. This should be a function that returns a
boolean
value. Should the value evaluate tofalse
when the precondition is called, the precondition is failed.2
optional, default value=nil
Name by which this precondition function may later be removed with
narrative_event:remove_precondition
.3
optional, default value=nil
Script message to transmit in the event that this precondition fails. This can either be a
string
or an indexedtable
of strings if multiple messages are required.Returns:
nil
defined in ../../warhammer/working_data/script/_lib/lib_campaign_narrative_events.lua, line 701
-
narrative_event:remove_precondition(
namestring
)
-
Removes a previously-added precondition by name.
Parameters:
1
Name of precondition to remove.
Returns:
nil
defined in ../../warhammer/working_data/script/_lib/lib_campaign_narrative_events.lua, line 745
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(
preconditionfunction
, [
namestring
])
-
Adds an advice precondition function.
Parameters:
1
Advice precondition function. This should be a function that returns a
boolean
value. Should the value evaluate tofalse
when the precondition is called, the precondition is failed.2
optional, default value=nil
Name for this advice precondition, by which it may be later removed with
narrative_event:remove_advice_precondition
.Returns:
nil
defined in ../../warhammer/working_data/script/_lib/lib_campaign_narrative_events.lua, line 784
-
narrative_event:remove_advice_precondition(
namestring
)
-
Removes a previously-added advice precondition by name.
Parameters:
1
name
Returns:
nil
defined in ../../warhammer/working_data/script/_lib/lib_campaign_narrative_events.lua, line 827
Trigger messages must be added to a narrative event. A narrative event will only trigger when a trigger message is received. One or more trigger messages 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(
messagestring
, [
conditionfunction
], [
namestring
])
-
Adds a trigger message and condition. If the narrative event has been started and the supplied script message is received, and the optional condition passes, and no preconditions fail, then the narrative event will attempt to trigger.
Parameters:
1
Message name.
2
optional, default value=nil
Conditional function to execute when the supplied message is received. The condition function will be passed the message context. If the function returns
true
then the check passes. If no function is specified then the check will always pass.3
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:
nil
defined in ../../warhammer/working_data/script/_lib/lib_campaign_narrative_events.lua, line 880
-
narrative_event:remove_trigger_condition(
namestring
)
-
Removes a previously-added trigger condition by name.
Parameters:
1
name
Returns:
nil
defined in ../../warhammer/working_data/script/_lib/lib_campaign_narrative_events.lua, line 942
Some narrative events may not wish an intervention to trigger at all, even in singleplayer. These narrative events would typically not display any information to the player and would be a hidden part of a greater sequence e.g. they might just set a value in the savegame or advice history and return. narrative_event:set_force_no_intervention
can be used to force a narrative event to not bother creeating an intervention.
-
narrative_event:set_force_no_intervention([
valueboolean
])
-
Forces the narrative event to not bother creating an intervention and instead trigger its contents directly, as it would in multiplayer mode. Missions associated with this narrative event will still be triggered, but associated advice will not be shown.
Parameters:
1
optional, default value=true
value
Returns:
nil
defined in ../../warhammer/working_data/script/_lib/lib_campaign_narrative_events.lua, line 966
Some narrative events may wish to configure the intervention
that is created internally. This can be done by setting a configuration callback with narrative_event:add_intervention_configuration_callback
. This could be used to allow the intervention to play before a battle sequence has been completed or when a fullscreen panel is showing, for example.
-
narrative_event:add_intervention_configuration_callback(
callbackfunction
)
-
Adds a configuration callback for the
intervention
object the narrative event may create internally (interventions are created in singleplayer mode only). If any configuration callbacks have been supplied then they are called as the intervention is created, which is generally just as it's triggered. Configuration callbacks will be passed the intervention object as a single argument, which they can then make configuration calls upon.
Setting a configuration callback allows calling scripts to tailor aspects of the intervention's presentation, such as allowing it to trigger over the top of fullscreen panels or not on the player's turn.
Multiple configuration callbacks may be added to a narrative event. They will be called in the order that they were added.Parameters:
1
callback
Returns:
nil
defined in ../../warhammer/working_data/script/_lib/lib_campaign_narrative_events.lua, line 992
-
narrative_event:start([
trigger immediatelyboolean
])
-
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
optional, default value=false
trigger immediately
Returns:
nil
defined in ../../warhammer/working_data/script/_lib/lib_campaign_narrative_events.lua, line 1020
Narrative Queries
For an overview of the narrative events system see the narrative
topic page.
Narrative queries represent decision points within a narrative structure. When triggered, a narrative query will run a supplied function query and may trigger script messages depending upon the result. Other narrative objects listening for those messages can then act upon the result of the query. See the page about the script_messager
for more information about script messages (they are different-but-equivalent to script events).
All the data associated with a narrative query is supplied to it when it's constructed. Of particular note is the query records data structure - see the documentation of narrative_query:new
for more information.
Once constructed, a narrative query is started by calling narrative_query:start
. This starts its internal trigger listeners.
A narrative query triggers when it receives one of the trigger messages specified on creation (and the faction information contained in the message context matches the faction registered with the narrative query). At this point, all query functions supplied to the narrative event will be run, in order of registration. Each function will be passed the message context supplied to the narrative query as a first argument and the narrative query itself as a second. The query function can use the narrative query object to store data that other query functions that are about execute can read, if required.
For any query that passes (i.e. the query function returns true) the related pass script message is triggered. Where a query doesn't pass, and a fail message was specified in the query setup, that fail message is triggered.
Unlike narrative_event
and narrative_trigger
objects, narrative queries are stateless and do not save any information into the savegame. This means that any narrative query can trigger multiple times. The narrative event framework is designed so that narrative events and triggers should only be issued once, however, so this should be avoided.
Narrative queries should work as expected in multiplayer mode.
Narrative queries output diagnostic information on the Lua - Narrative
console spool.
-
narrative_query:new(
namestring
,
faction keystring
,
trigger messagestring
,
query recordstable
)
-
Creates and returns a narrative query object. As with all narrative objects a unique name and faction key to which the query applies must be supplied.
The query records table must be an indexed table containing one or more subtables. Each subtable should contain elements at the following keys:
Key Data Description
message
Message to trigger if the related query function returns true (or a value that equates to true). This can be a single string or a table of strings if multiple pass messages are desired. fail_message
Optional message to trigger if the related query function returns false (or a value that equates to false). This can be a single string or a table of strings if multiple pass messages are desired. query
A function that should return a boolean value which determines whether the query passes or fails. The function will be passed two arguments: - The context of the message which triggered the narrative query.
- The narrative query object itself.
See theUsage
section of this documentation for a declaration example.Parameters:
1
Unique name amongst narrative query objects.
2
Key of faction, from the
factions
database table, this narrative query is related to.3
String name of message which triggers this narrative query. This may also be a
table
of multiple string message names, any of which will trigger the query.4
Query records - see the function documentation for a description of the data format to supply here.
Returns:
narrative querynarrative_query
defined in ../../warhammer/working_data/script/_lib/lib_campaign_narrative_events.lua, line 1616
A narrative query object is created and returned by calling narrative_query:new
. Once created, functions on a narrative_query
may be called in the form showed below.
Example - Specification:
<narrative_query_object>:<function_name>(<args>)
Example - Creation and Usage:
-- name, faction_key, trigger_messages, query_records
local nq_advice_level = narrative_query:new(
"advice_level",
"wh3_main_ksl_the_ice_court",
{"Example1", "Example2", "Example3"},
{
-- all queries will be run when narrative_query triggered
{
message = "ExampleAdviceLevelHigh",
query = function(context, nq)
return common.get_advice_level() == 2
end
{,
{
message = "ExampleAdviceLevelLow",
query = function(context, nq)
return common.get_advice_level() == 1
end
{,
{
message = "ExampleAdviceLevelMinimal",
query = function(context, nq)
return common.get_advice_level() == 0
end
{
}
)
-- starting the narrative query
nq_advice_level:start()
-
narrative_query:start()
-
Starts the narrative query's listeners.
Returns:
nil
defined in ../../warhammer/working_data/script/_lib/lib_campaign_narrative_events.lua, line 1746
It may be desirable for a narrative query to not immediately return a result when it is triggered, such as if a multiplayer query is run with campaign_manager:progress_on_mp_query
. narrative_query:defer
may be called while is query is actively processing to instruct the query not to act on any result at that moment. At a later time narrative_query:retrigger
may be called, which re-runs the query. In the interim, scripts can have prepared the information that the query needs to successfully complete.
-
narrative_query:defer()
-
Defers the query, instructing it to not transmit any success or failure messages at that time. The query may be re-run with
narrative_query:retrigger
.
This function may only be called from within one of the narrative query's condition callbacks.Returns:
nil
defined in ../../warhammer/working_data/script/_lib/lib_campaign_narrative_events.lua, line 1889
-
narrative_query:retrigger()
-
Retriggers a deferred query.
Returns:
nil
defined in ../../warhammer/working_data/script/_lib/lib_campaign_narrative_events.lua, line 1903
Narrative Triggers
For an overview of the narrative events system see the narrative
topic page.
Narrative triggers monitor game conditions in order to trigger other objects within the narrative system. All narrative events, or chains of narrative events, should ultimately be started by a narrative trigger.
One or more game script event/condition checks are registered with the narrative trigger either as it's created with narrative_trigger:new
or later with narrative_trigger:add_monitor_event
. When the narrative trigger is subsequently started when narrative_trigger:start
is called, it starts a listener for each supplied event/condition and, if the event is received and the related condition is met, triggers one or more script messages that can start other objects in the narrative event system. Narrative triggers can also listen for script messages to know when to trigger - these can be added with narrative_trigger:add_monitor_message
- although it's intended that narrative triggers should primarily listen for script events rather than messages.
Note the distinction between script messages and script events - while narrative triggers can listen for script events and messages from the game (or other scripts) to know when to trigger, the communication with other narrative objects happens exclusively with script messages. Script messages are a script-only parallel mechanism to script events, see the script_messager
documentation for more information.
In most cases, all data relevant to the narrative trigger is supplied during construction, when narrative_trigger:new
is called. Additional script events/conditions to monitor can be added after creation by calling narrative_trigger:add_monitor_event
.
Once created, a narrative trigger will begin its monitors when narrative_trigger:start
is called. Like narrative events and queries, narrative triggers are intended to only trigger once per-campaign playthrough. If a narrative trigger finds in the savegame data that it has triggered before it will not start its listeners when narrative_trigger:start
is called.
Narrative triggers should work in multiplayer mode. Narrative triggers should only listen for model game events in multiplayer mode to allow scripts on different physical machines to maintain synchronicity.
Like other narrative objects, narrative triggers output diagnostic information on the Lua - Narrative
console spool.
Invididual event/condition pairs can be set up to trigger immediately or not. Should an event/condition pair not be set up to trigger immediately then the narrative trigger will fire its trigger messages(s) within an intervention, which means that the message may not be triggered straight away. This can help reduce the intrusiveness of the narrative event system by spacing out the delivery of narrative events over time.
In multiplayer mode, where interventions are not supported, trigger messages are always fired immediately.
Narrative triggers may also be set up with start messages. Should one or more start message be registered then the narrative trigger will not start its main event/condition monitoring process until a start message is received from another object within the narrative event system. This can be useful in certain circumstances, for example to listen for the start of a particular faction's turn but only after another mission in the narrative event system has completed. If no start messages are specified the narrative trigger starts its main monitoring process immediately when narrative_trigger:start is called.
Cancel messages may also be set up for narrative triggers. These allow other narrative objects to cancel the trigger's main monitoring process, which can be used to stop a trigger from firing if some other condition is met within the narrative event system.
-
narrative_trigger:new(
name
string
,
faction key
string
,
target message
string
,
main event records
[table
],
start message
[string
],
cancel messages
[string
],
intervention priority
[number
]
) -
Creates and returns a narrative trigger object. As with all narrative objects a unique name and faction key to which the trigger applies must be supplied.
The main events and conditions table must be an indexed table containing one or more subtables for each event/condition pair. Each subtable should contain elements at the following keys:
Key Data Description
event
Game event to listen for. This should be a model event and not a UI event to prevent the game desynchronising in multiplayer mode. condition
Condition check to perform at the time the related event is received. This should be a function
which returns a boolean value. When called, the function will be passed the event context and the narrative trigger object as two separate arguments.In common with other event/condition systems elsewhere, theboolean
valuetrue
may be supplied here in place of a function, in which case the condition always passes.immediate
Optional boolean value which, if set to true, forces the narrative trigger to fire its trigger events immediately if this event/condition pair pass. If this value is false or is not supplied, the target message(s) are fired in an intervention which can delay their issue. In multiplayer mode the target message(s) are always fired immediately.
See theUsage
section of this documentation for a declaration example.Parameters:
1
Unique name amongst narrative query objects.
2
Key of faction, from the
factions
database table, this narrative query is related to.3
String message which this narrative trigger fires when any event/condition pair are met. This may also be a
table
of multiple string message names, in which case all will be triggered.4
optional, default value=nil
Main event and condition records. See the function documentation above for a description of the data format to supply here. This may be left blank, with main listeners added later using either
narrative_trigger:add_monitor_event
ornarrative_trigger:add_monitor_message
.5
optional, default value=false
Message on which to start this trigger's main event monitors. This can be supplied as a single string or a
table
of multiple string message names.If no start messages are supplied then the narrative trigger will start its main event monitors as soon as it is started.
6
optional, default value=false
Narrative messages on which to cancel the narrative trigger. This can be supplied as a single string or a
table
of multiple string message names.7
optional, default value=60
Priority at which to trigger the internal
intervention
object, if one is declared. See intervention documentation for more information about intervention priorities.Returns:
narrative triggernarrative_trigger
defined in ../../warhammer/working_data/script/_lib/lib_campaign_narrative_events.lua, line 2060
A narrative trigger object is created and returned by calling narrative_trigger:new
. Once created, functions on a narrative_trigger
may be called in the form showed below.
Example - Specification:
<narrative_trigger_object>:<function_name>(<args>)
Example - Creation and Usage:
-- name, faction_key, target_messages, main_event_and_condition_records, start_messages, cancel_messages, intervention_priority
local nt_player_starts_turn_ten = narrative_query:new(
"player_starts_turn_ten",
"wh3_main_ksl_the_ice_court",
"ScriptEventPlayerStartsTurnTen",
{
{
event = "ScriptEventHumanFactionTurnStart",
condition = function(context, nt)
return context:faction():name() == "wh3_main_ksl_the_ice_court"
end,
immediate = true
{
},
nil,
"CancelPlayerStartsTurnTen"
);
-- calling a function on the object once created
nt_player_starts_turn_ten:start()
-
narrative_trigger:has_triggered_this_campaign()
-
Returns whether this narrative event has triggered in this campaign save.
Returns:
has triggeredboolean
defined in ../../warhammer/working_data/script/_lib/lib_campaign_narrative_events.lua, line 2215
-
narrative_trigger:add_monitor_event(
eventstring
,
conditionfunction
, [
trigger immediatelyboolean
])
-
Adds a event/condition monitor record to this narrative trigger. This should only be called after the creation of the narrative trigger, but before it is started with
narrative_trigger:start
.Parameters:
1
Event name.
2
Condition function. This function will be called when the specified event is received, and will be passed the event context and the narrative trigger object as two arguments. It should return a value that evaluates to true if the condition passes, or otherwise if the condition fails.
Alternatively the
boolean
valuetrue
may be supplied in place of a function, in which case the condition always passes.3
optional, default value=true
Instructs the narrative trigger to fire its target messages immediately if this event/condition pair pass. If
false
is specified here, and it's a singleplayer game, the triggering of the target messages happens within an intervention.Returns:
nil
defined in ../../warhammer/working_data/script/_lib/lib_campaign_narrative_events.lua, line 2235
-
narrative_trigger:add_monitor_message(
messagestring
, [
conditionfunction
], [
trigger immediatelyboolean
])
-
Adds a script message/condition monitor record to this narrative trigger. This should only be called after the creation of the narrative trigger, but before it is started with
narrative_trigger:start
.Parameters:
1
Message name.
2
optional, default value=nil
Condition function. This function will be called when the specified message is received, and will be passed the message context and the narrative trigger object as two arguments. It should return a value that evaluates to true if the condition passes, or otherwise if the condition fails.
Alternatively the
boolean
valuetrue
may be supplied in place of a function, in which case the condition always passes.3
optional, default value=true
Instructs the narrative trigger to fire its target messages immediately if this event/condition pair pass. If
false
is specified here, and it's a singleplayer game, the triggering of the target messages happens within an intervention.Returns:
nil
defined in ../../warhammer/working_data/script/_lib/lib_campaign_narrative_events.lua, line 2275
-
narrative_trigger:set_should_setup_cancel_listeners_with_start_listeners([
valueboolean
])
-
Sets whether the narrative trigger should start cancel message listeners with start message listeners. If the narrative trigger is set up with both start messages and cancel messages, then by default the cancel message listeners are not started until the start messages are received. Use this function to change this behaviour and allow the narrative trigger to be cancelled before a start message is received.
Parameters:
1
optional, default value=true
value
Returns:
nil
defined in ../../warhammer/working_data/script/_lib/lib_campaign_narrative_events.lua, line 2315
-
narrative_trigger:add_start_callback(
calllbackfunction
)
-
Adds a start callback to the narrative trigger. This will be called when the narrative trigger starts its main monitoring processes, either when the start message is received or on startup (if no start message was specified). If the game is saved and reloaded at this point, causing the main monitors to be restarted, then any start callbacks are called again.
A boolean flag will be passed to any start functions to indicate whether the main monitors are being started from a savegame. If the main monitors are not being started from a savegame then it means a start message has just been received - in this case the start message string is supplied to each callback as a second argument.Parameters:
1
calllback
Returns:
nil
defined in ../../warhammer/working_data/script/_lib/lib_campaign_narrative_events.lua, line 2333
-
narrative_trigger:add_stop_callback(
calllbackfunction
)
-
Adds a stop callback to the narrative trigger. This will be called when the narrative trigger stops its main monitoring processes, either when a main monitor is satisfied and fires the target message(s), or when a cancel event is received while the main monitors are running. Each stop callback will be passed a flag to indicate whether the narrative trigger's target messages were fired.
Parameters:
1
calllback
Returns:
nil
defined in ../../warhammer/working_data/script/_lib/lib_campaign_narrative_events.lua, line 2346
-
narrative_trigger:start()
-
Start the narrative trigger. If any start messages have been registered with the narrative trigger then a listener for these is started, otherwise the main event/condition listeners are started.
Some main monitor records must have been added to the narrative trigger prior to this function being called, either during construction (seenarrative_trigger:new
) or afterwards withnarrative_trigger:add_monitor_event
ornarrative_trigger:add_monitor_message
.Returns:
nil
defined in ../../warhammer/working_data/script/_lib/lib_campaign_narrative_events.lua, line 2385
-
narrative_trigger:trigger_message(
messagestring
)
-
Force this narrative trigger to trigger a message, associated with the faction related to this narrative trigger.
Parameters:
1
message
Returns:
nil
defined in ../../warhammer/working_data/script/_lib/lib_campaign_narrative_events.lua, line 2737
-
narrative_trigger:force_main_trigger([
reasonstring
], [
immediateboolean
])
-
Instruct this narrative trigger to act as if one of its main monitors has been triggered. The narrative trigger must be in the correct phase, where its main monitors are active. A reason string may be supplied for output purposes.
Parameters:
1
optional, default value=nil
Reason string.
2
optional, default value=true
Force the narrative trigger to trigger its target messages immediately. If this is set to
false
, and it's a singleplayer game, then the narrative trigger will trigger the target messages within an intervention.Returns:
nil
defined in ../../warhammer/working_data/script/_lib/lib_campaign_narrative_events.lua, line 2745