Fallout 4

Functions
Functions allow you to call a specific piece of code via Papyrus, like showing messages, adding items, etc.

Notes

  • The types have to always meet exactly their Papyrus equivalent, no exceptions and no auto-casting,
    meaning that you can't pass an int to a float or an Actor to an ObjectReference parameter, for example.
  • The form IDs have to be loadorder independent, meaning that for normal forms, the first two digits are removed ("0xXX123456" -> "0x123456")
    and for light (esl) forms, the first five digits are removed ("0xFEXXX123" -> "0x123").
  • The values of the 'pluginName', 'scriptName', 'functionName' and 'propertyName' keys are case-insensitive.


Events
There are two types of events a function can listen to under the "eventName" key.
If the event gets invoked, the function runs, if not, the function can only run through Papyrus.
  • "OnGameStart" - Runs on session start.
  • "OnGameLoad" - Runs on session start and on game load.


Example 1 - Global Function
This shows a message box on game start.
{
    "functions": [
        {
            "eventName": "OnGameStart",
            "scriptName": "Debug",
            "functionName": "MessageBox",
            "args": [
                {
                    "type": "string",
                    "value": "Hello, World!"
                }
            ]
        }
    ]
}


Example 2 - Member Function
This will add 100 caps to the player on game load.
{
    "functions": [
        {
            "eventName": "OnGameLoad",
            "scriptName": "Actor",
            "pluginName": "Fallout4.esm",
            "formID": "0x14",
            "functionName": "AddItem",
            "args": [
                {
                    "type": "form",
                    "scriptName": "Form",
                    "pluginName": "Fallout4.esm",
                    "formID": "0xF"
                },
                {
                    "type": "int",
                    "value": 100
                },
                {
                    "type": "bool",
                    "value": false
                }
            ]
        }
    ]
}

Article information

Added on

Edited on

Written by

SoleVaultBoy

0 comments