[WIP] This mod is still just a rough draft, and is nowhere close to being functional
storyline
is a modding API which allows mods/games to add a simple linear
storyline, on a per-player basis.
storyline
provides two important components to mods to help develop a storyline:
- Events: These are the fundamental units of the storyline.
- Scripts: These define a sequence of events, and trigger them one-by-one.
{
description = "",
on_run = function(name)
}
An event definition consists of the event's description, and its on_run
callback. The on_run
callback is mandatory, and can be used to set-up
the game environment, for example.
{
events = { event1, event2, event3 },
on_begin = function(name),
on_end = function(name),
on_trigger_event = function(name)
}
A script definition, among others, consists of a list of event IDs, which is
the heart of this mod. The other fields are the on_begin
, on_end
, and
on_trigger_event
callbacks.
- Loads data from mod storage into memory.
- Saves data from memory into mod storage.
- Event registration function; takes an event definition table as a parameter.
- Throws an error if the event definition is invalid.
- Returns the ID of the registered event.
- Returns the event definition table corresponding to the given event ID.
- Script-setting function; takes a player name and a script definition table as parameters.
- Throws an error if the script definition is invalid.
- Returns the script definition (or
nil
) of the storyline of a given player.
- Commences the script of the given player's storyline. Initializing the script has been separated from setting the script, to allow deferring the execution of the script if required.
- Runs the script's
on_begin
callback if it exists, and then the first event'son_run
is invoked.
- Sets the current event of the given player's storyline as complete.
- Runs the script's
on_trigger_event
callback if it exists, and then executes the next event'son_run
callback. - Note: It's the downstream mod's responsibility to track the progress of
player's events. As
storyline
has no knowledge of event progress, the downstream mod must callstoryline.finish_event
to notifystoryline
that an event has been completed.
Runs when a script is initialized during a call to storyline.begin_script
.
Runs when an event is complete, just before the new event's on_run
is executed.
Runs when a script is over.
Executed after on_trigger_event
, when the script triggers an event.