Advanced Papyrus Integration - Neanka/MCM_0.1_AS3 GitHub Wiki

Scripts can be informed when the value of a control changes by doing one of the following:

  • Adding a Papyrus action to a MCM control to pass values to a specified function when they are changed.
  • Registering for a setting-changed event that the MCM dispatches whenever the user changes a setting.

Control Action

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": {
    "type": "CallFunction",
    "form": "MCM_Demo.esp|800",
    "function": "OnSliderValueChanged",
    "params": ["{value}"]
  }
}

Event Registration

Register for the OnMCMOpen event to be notified when the user opens the MCM menu. NOTE: the menu will be rendered by the time your Papyrus script is run, so if you want to make changes that will affect the menu, call MCM.RefreshMenu() in your OnMCMOpen function. Register for the OnMCMSettingChange event to be notified when the user changes a setting. To receive events from a specified mod only, use the pipe symbol (|) followed by the mod name. Otherwise, the calling script will receive setting change events from all MCM menus.

Event OnQuestInit()
    playerref = Game.GetPlayer()
    RegisterForRemoteEvent(playerref, "OnPlayerLoadGame")
    RegisterCustomEvents()
    Update()
EndEvent

Event Actor.OnPlayerLoadGame(Actor akSender)
    RegisterCustomEvents()
    Update()
EndEvent

Function RegisterCustomEvents()
    RegisterForExternalEvent("OnMCMOpen", "OnMCMOpen");
    RegisterForExternalEvent("OnMCMSettingChange|MCM_Demo", "OnMCMSettingChange")
EndFunction

Function Update()
    ;update whatever variables and properties that are needed by MCM:
    ;(1) when the user loads a saved game, or
    ;(2) when MCM changes your global variables or script properties via controls
EndFunction

Function OnMCMOpen()
    Update()
    MCM.RefreshMenu()
    Debug.Notification("MCM Menu was opened")
EndFunction

Function OnMCMSettingChange(string modName, string id)
    If (modName == "MCM_Demo") ; if you registered with OnMCMSettingChange|MCM_Demo this should always be true
        If (id == "control_id")
            Debug.Notification("control_id value was changed!")
        EndIf
    EndIf
EndFunction

; Can be added to the config.json as an action/CallFunction to update internal properties and variables after MCM changes any of them
Function MCMApply()
    Update()
EndFunction