Integration - lynnpye/sl_triggers GitHub Wiki

Types of Integration

SLT has been expanded to allow more external interaction, meaning rather than only being able to trigger scripts from the built-in triggered events in SLT, mod and modpack authors can use SLT with their mods, expanding the functionality of other mods without having to modify them.

Let's look over some of the approaches you can take to request scripts be run by SLT.

Asking SLT To Run Scripts

ModEvent

"sl_triggers_SLTRequestCommand"

usage:

  • targetedActor.SendModEvent("sl_triggers_SLTRequestCommand", "scriptname")
    • if everything checks out (valid script, valid actor, etc.), the script will begin executing on the targetedActor

"sl_triggers_SLTRequestList" (available v111)

usage:

  • If your list should be attached via StorageUtil to the Form that sends the mod event, either pass 0.0 as the float argument or let it default
    • FormYouWantStorageUtilDataAnchoredTo.SendModEvent("sl_triggers_SLTRequestList", "yourStorageUtilStringListKey")
  • If your list should be attached via StorageUtil to the the global namespace, pass the value 1.7 (yes, specifically 1.7, I am weird that way)
    • FormYouWantStorageUtilDataAnchoredTo.SendModEvent("sl_triggers_SLTRequestList", "yourStorageUtilStringListKey", 1.7)
  • Upon receiving the event, SLT will populate the indicated StorageUtil key with the list of commands.
  • If you put an event name in the first index of the list prior to calling, SLT will also fire that event back to you once the list is populated.

API

If you would prefer to script against an API, SLT provides sl_triggersAPI, and ships with a file, sl_triggersAPI.psc.headeronly which, as the name implies, includes only the headers, convenient for including in your builds.

The API includes the following functions:

  • int GetVersion() global - returns the SLT mod version number
  • string[] GetScriptsList() global - returns the list of SLT scripts available for execution
  • RunScript(string _scriptname, Actor _theActor = none) - executes the requested SLT script on the specified Actor; defaults to the Player if not specified; uses the ModEvent approach

Console Command

If console commands are more your style, those are available as well.

Fair warning: the current approach hooks the console window and watches for error messages when my slt command is run, then does the work and repaints the text of the console window with happy friendly SLT messages. I am not sure this will work if scripted via Papyrus script and something like ConsoleUtil-Extended (which allows you to run custom console commands from Papyrus script calls). But manually it's just fine. See the Console Commands page for usage info.

Extension

And for the more adventurous souls, you can create an SLT extension. I will create an example in the future, but for now, you can look at sl_triggersExtensionCore.psc (and the base class for it, sl_triggersExtension.psc) for fairly simple examples. See the Extensions page for more details.

Broadly speaking, an extension consists of your Quest, extending the SLT sl_triggersExtension base class, overriding a few functions like GetExtensionKey() and GetFriendlyName() and making sure to call SLTInit() in your OnInit(). This lets SLT handle the lifecycle of your Extension with regard to SLT functionality and signals SLT will manage your trigger and extension settings data for you. Of course, there's nothing saying you can't have your extension settings and trigger data somewhere else, but if so, you will have more customization to do and SLT will no longer manage these aspects for you.

Asking SLT to Interact With Your Mod

As you can imagine, extending SLT's abilities to include interacting with a new mod is a little more involved and technical than reaching out and asking it to do what it already knows how to do well. In essence, the only way SLT can interact with other mods is through the operations performed in SLT scripts.

Tapping Into Existing Functionality

SLT already offers script authors the ability to send mod events, so documenting any such interfaces cleanly will obviously help.

Creating a Command Library

First off, I really should rename that to a Function Library, but I digress.

If you want to maximize the ability for SLT to operate on your mod and don't want to wait for an SLT maintainer to add the functionality into the base library, you can create a command library. A command library is nothing more than a compiled .psc (i.e. .pex file) with global functions having specific signatures required by SLT, along with a simple JSON file placed in an sl_triggers folder to let it know of the library's existence. See the Command Libraries page for more details.

Although it requires Papyrus scripting knowledge, if you are already a mod author looking to create an integration between SLT and your mod, you probably already have the necessary scripting skills. If not, feel free to ask for some assistance. :)