Skyrim Special Edition
0 of 0

File information

Last updated

Original upload

Created by

LeucisticDinosaur

Uploaded by

LeucisticDinosaur

Virus scan

Safe to use

About this mod

A collection of examples, including script tricks for mod compatibility, a resource for interacting with Survival Mode fatigue, and several xEdit patchers.

Permissions and credits
Changelogs
You're free to use, modify, or re-distribute anything from these examples, no permission needed.

Quick descriptions below; I've tried to document scripts enough that they'll be understandable.  I've also listed a few pointers to resources or info that I wish I'd learned sooner in my modding journey at the bottom of this page.

While the scripts in these examples have been working well for me, some of them haven't been tested thoroughly outside of my own (heavily-modded) setup, so please let me know if you see any issues!


Scripts

Tweakable leveled list distribution
Spoiler:  
Show
One downside of distributing items with a script is that users who are accustomed to adjusting leveled lists for balance or preference may be unable to do so.  This example demonstrates one way to automatically add items to a base-game leveled list in a way that allows users to control item spawn rates via a global variable or even modify the lists in xEdit themselves.  Mid-game changes to the lists or global variable should work correctly.

The example plugin adds some thematically-appropriate scrolls to Thalmor wizards and Vigilants.  Scrolls begin to drop at level 10, all scrolls can drop at level 40 and above, and rarity is controlled by a pair of global variables.

Interacting with Survival Mode fatigue
Spoiler:  
Show
I developed a script for my mod Growable Coffee for a magic effect that changes Survival Mode fatigue when it begins and ends.  This example includes the script and a small example esp that adds potions that restore, damage, and fortify fatigue.  After drinking the potions you'll need to wait a few seconds for the changes to register with Survival Mode.

To work around concurrency issues inherent to Survival Mode's implementation, this script does not allow you to apply multiple fatigue changes simultaneously.  In the example plugin, if any effects are applied within 5 seconds of each other, only the last will take effect; this is enforced by all effects having a keyword in common that allows them to dispel each other.  If two instances of this script are attached to different effects that don't dispel each other and happen to apply a fatigue change near-simultaneously, it is possible that the player could end up with a fatigue stage effect (Tired / Debilitated / etc) that does not match their global variable fatigue level.  This discrepancy should be resolved the next time Survival Mode runs an update.

Please be aware that you will likely be unable to recompile this script!  It uses several functions and properties of Survival_NeedExhaustionQuest, so if you need to recompile the script you may also need to decompile survival_needbase.pex and survival_needexhaustion.pex, gut any references to other scripts for which you don't have the source, and then recompile them before recompiling this script.  I made the script as flexible as I could with regard to properties, so hopefully you won't need to do this.

Low-conflict growable plants
Spoiler:  
Show
Note: check out FormList Manipulator for an alternative way to do this.

Growable plants are set up by adding several associated records to FormLists.  Unfortunately this means that if you have multiple mods that add new growable flora, only the last one in your load order will work correctly without a patch, and these changes won't be correctly merged by tools like Wrye Bash.  This resource demonstrates how to add items to those FormLists via script instead, similar to script-based leveled item distribution.  The example plugin provided makes Nirnroot and Crimson Nirnroot growable with the vanilla model (which looks strange with small planter soil, but hopefully proves the concept).

Please note that if you have another mod that makes Nirnroot and/or Crimson Nirnroot growable, a failure message from this mod will probably pop up the first time you pick up either ingredient.  This is because it's already in the lists.  Remove any duplicates from this plugin's FormLists before using.

This method also works generally for adding to FormLists without needing manual patches.  Because FormLists are often sensitive to the order of their items in a way that leveled lists aren't, the example plugin adds items to lists the first time you pick up an item that can be used as a seed (to avoid conflicts that could occur if multiple mods added items to that FormList at the start of the game).  If you're working with different FormLists, take a look at the "Adding to a FormList by script" example.

Adding to a FormList by script
Spoiler:  
Show
Note: check out FormList Manipulator for an alternative way to do this.

This example uses the same basic method as the growable plants example, but contains a more general script for adding items from one FormList to another.  This script demonstrates adding items on both (1) an item in the FormList being added to the player's, or another reference's, inventory; and (2) a tracked stat such as dragons killed / locations discovered first updating.  It's also entirely possible to simply add to a FormList upon the quest initializing.  The idea here is just to reduce script load right at the start of a playthrough (especially for users who don't have an alternate start mod!) and give some more control over what order items will be added in, for cases where the order of a FormList matters.

The example plugin adds items to three lists:
(1) Several alcoholic drinks, both from the base game and DLCs, will be added to the list of drinks you can gift to a drunk the first time such a drink is picked up.
(2) Bees will be added to the list of critters that can appear during the day at some spawn points that normally generate blue and monarch butterflies (diurnal critter list); this occurs the first time you discover a new location, get a skill increase, or catch a butterfly or moth.
(3) Potions of Regeneration, Well-being, and Escape will be added to the list of healing potions that can be used in a handful of quests.  In the vanilla game I think this is just the list of potions that can be given to Valdr outside Moss Mother Cavern and to Wujeeta to cure her addiction.  Mods may use this list as well.


xEdit Scripts

Please note that any .pas files provided with these examples must be placed in the Edit Scripts directory under your xEdit install.  These scripts can then be run on a set of records loaded in xEdit (right click > Apply Script, and select the file name).

Armor and weapon consistency
Spoiler:  
Show
This file contains an xEdit patcher that runs on weapons and armor and, based on the keywords on those items, (1) generates crafting and tempering recipes equivalent to base-game ones and (2) attempts to make damage, speed, and other statistics consistent with base-game ones for items with the same keywords.

Recipes and stats rely on keywords to identify what kind of item a record is.  For example, a WEAP with WeapTypeSword and WeapMaterialSteel will be set up with the stats and recipes of a vanilla steel sword.  Items tagged as clothing will also be given a simple crafting recipe using linen wraps.  Arrows are not currently supported.  Any added recipes you don't want can be safely deleted.

As of version 1.1 of this example there are three settings that may be modified to control the script's behavior (starting at line 484):
add_recipes := True; // generate crafting recipes
add_temper_recipes := True; // generate tempering recipes
modify_stats := True; // change item stats to match reference one


Editing any of these to False instead of True will skip that portion of the script.

Errors may not be very clear as to what the issue is; please let me know the message and script line if you see any errors!  One good thing to confirm first is that the items you are running the patcher on all have both a type and material keyword, and that there are recipes for that kind of item in one of Skyrim.esm, Dawnguard.esm, or Dragonborn.esm.

Generating items and recipes for enchantments
Spoiler:  
Show
This file contains a small example xEdit patcher that attempts to identify base enchantments in files it is run on, then auto-generates several items and crafting recipes for each.  This script is most likely not useful except as a mod author resource.

I've confirmed the script mostly works correctly on vanilla and Summermyst enchantments.  Some unique enchantments, such as the vanilla Amulet of Articulation enchantment, will be erroneously included.  Adding a MagicDisallowEnchanting keyword check would be one way to work around this.  The script also doesn't have anything implemented to distinguish between ordinary enchantments and those that don't scale with enchantment power (like Waterbreathing).

Generating scrolls and staves
Spoiler:  
Show
This file contains an xEdit patcher that runs on spell tomes, attempts to identify spells that do not already have a corresponding staff or scroll, and generates staves and scrolls for each.

Settings are available to control which types of spells will have scrolls and staves generated:
    skip_conc_scrolls := True; // do not generate scrolls for concentration spells
    skip_twohanded_staves := True; // do not generate staves for spells requiring two hands
    skip_master_staves := False; // do not generate staves for master-level spell


The first pop-up also allows you to set whether you'd like to only allow scrolls to use the base magic effect for spells which have an upgraded version with higher-level perks.  If you select the option for the patcher to remove perk effects, Bound Bow won't benefit from the Mystic Weapon perk even if you have it, for example.


Other resources / info

Script decompilation
If you wish to understand what another mod is doing in its scripts but only have the compiled .pex files, the Champollion decompiler is a fantastic resource.  Please note that the decompiler is unable to distinguish between function and event blocks, so you generally will not be able to decompile and re-compile scripts without some manual fixing.

CK script editor & compilation nonsense
If a script file is too long, the CK editor won't allow you to add any more characters.  I don't know what exactly this limit is, but I tend to hit it at around 600 lines of script.  However there is no actual file size limit enforced by the compiler; if you hit this character limit, it's easy to work around by using an external text editor to add whatever you'd like to the script source file, then compiling in the CK.  There is no need to close and re-open the CK, it'll pick up the modified source file fine.  I have confirmed that Notepad and vim (via WSL) both work, and that this all works when using MO2's virtual file system as well.

Perk tricks
There are many effects accessible through perk entry points that cannot be implemented otherwise.  Please be aware that not all perk effects will work correctly for NPCs (for example, adding an ability via a perk works only for the player).