Skip to content

Papyrus Integration

Parapets edited this page Jul 5, 2021 · 10 revisions

Creating a config script

A config menu is controlled by a Papyrus script. If you want a global script that's not attached to any particular actor or object in the game world, the common method is to use a quest script. Such a quest script has to be attached to an actual quest that has the sole purpose of binding the script. It doesn't do anything quests would normally do.

MCM Helper's config menus have to extend MCM_ConfigBase, which is a script provided by us.

Consequently, to create a new config menu for your mod, you have to

  • create a new script that will control your config menu. For now, it doesn't have to be more than this:
    Scriptname MyConfigMenu extends MCM_ConfigBase

  • create a new quest and attach your script to it.

After this, there is one, very important, thing left to do here. Each config menu has to run some maintenance code when the game is reloaded. This has to be set up manually:

  • In the quest you created, select the Quest Aliases tab and add a new reference alias. Name it PlayerAlias.
  • For Fill Type, select the player reference (Specific Reference, Cell any, Ref PlayerRef).
  • In the Scripts list, add SKI_PlayerLoadGameAlias.

This screenshot shows what the reload alias setup it looks like in the end.

Both this script setup and the Menu Layout step must be done in order for the menu to show up in the control panel.

Events

Your config script can implement events in order to respond to user actions. For instance, the OnSettingChange event is dispatched whenever the user changes a setting.

; Event raised when an MCM setting is changed.
Event OnSettingChange(string a_ID)
EndEvent

; Event raised when a config menu is opened.
Event OnConfigOpen()
EndEvent

; Event raised when a config menu is closed.
Event OnConfigClose()
EndEvent

Control Action

You can also add a Papyrus action to a control to pass its value to a specified function whenever it is changed.

Use the {value} keyword to substitute the value of a control in a Papyrus function call. Note that the data type of the parameter will match the value type of the control. See Setting Types, Storage, and Persistence for the data types.

When passing a constant value to a function, the desired data type can be specified by prefixing {i}/{b}/{f}/{s} to the value. This casts the value to an int, bool, float or string, respectively.
e.g. "{i}42"

Action types:

  • CallFunction
  • CallGlobalFunction
{
  ...
  "action": {
    "type": "CallFunction",
    "form": "MCM_Demo.esp|800",
    "function": "OnSliderValueChanged",
    "params": ["{value}"]
  }
},
{
  "text": "Demo Button",
  "type": "text",
  "help": "Displays a messagebox via a CallGlobalFunction action.",
  "action": {
    "type": "CallGlobalFunction",
    "script": "Debug",
    "function": "MessageBox",
    "params": ["Hello world!"]
  }
}