JIP LN NVSE Script Runner Introduction

From GECK
(Redirected from Script Runner Introduction)
Jump to: navigation, search

Introduction

Instead of running init quests in MenuMode 4 or GameMode, you can add event listeners via batch scripts. JIP LN NVSE scans the directory Data\nvse\plugins\scripts and runs files with certain prefixes on the following events:

gr_*.txt on game start,
gl_*.txt on game load,
gs_*.txt on game save,
gx_*.txt on game exit,
xm_*.txt on exit to the main menu,
gn_*.txt on new game (as of JIP LN 56.34),
ln_*.txt on new game and game load (as of JIP LN 56.95)

As of xNVSE 6.21, text scripts support practically full range of NVSE expressions, including loops and lambdas.

The most notable exception is the $ operator, which must be replaced with GetName or Inline Expressions:
instead of $sString, write (sString).

File size of a text script cannot exceed 16384 bytes.

What’s the catch?

These files are executed in the console environment, hence no resolution of Editor IDs by default, only Form IDs are allowed. There are a few ways to circumvent this.

Method One - Use JohnnyGuitar NVSE.

This method implies, that your mod already depends on JohnnyGuitar NVSE. With JohnnyGuitar NVSE, you can run scripts by their Editor IDs. As of xNVSE 6.0, Call is working as expected from text scripts.

call MyCustomUDF

Method Two – Determine your mod’s index, using a global variable, build reference variable for your UDF with BuildRef and run it.

int i
ref rUDF
set i to GetSourceModIndex AutorunDemoGlobal
set rUDF to BuildRef i 5719
call rUDF

In this method, we utilize availability of global variables in the console.

  • Create one constant global variable in your mod with any value and replace AutorunDemoGlobal with it.
  • Now we need Form ID of your User Defined Function in decimal representation. Open FNVEdit, you’ll see something like this 00004240 – the first two symbols are load-order-dependent mod index, last six are the form ID of your UDF. We need the latter. Paste them into any hex-to-dec convertor, for instance, this one, and get a number. Insert it in place of 5719 in the example.

Done, you can now use all NVSE features. A potential disadvantage here is the possibility of Form ID renumbering during mod merging.

Method Three – Use GetFormFromMod for vanilla and unmergeable mods.

If you want to modify only vanilla items or know for sure, that no one in their right mind will merge the target mod, then literal Form IDs for FalloutNV.esm, or GetFormFromMod and StringToRef for other plugins are perfectly fine. Let’s remove the quest flag from Rocket Souvenir:

SetFlagsLow 0 "0008E665"

Or make Stealth Suit Mk II a light armor:

ref rArmor
set rArmor to GetFormFromMod "OldWorldBlues.esm" "C12F"
SetArmorClass rArmor 1
SetWeight 17 rArmor
SetArmorAR 9 rArmor

Easy road – Declare your mod unmergeable.

ref rUDF
set rUDF to GetFormFromMod "MyCoolMod.esp" "800"
call rUDF

or

ref rOnDrink
set rOnDrink to GetFormFromMod "MyCoolMod.esp" "800"
SetOnUseAidItemEventHandler rOnDrink 1 "0005C365" ; AlchoholicDrinks

Notes

  • If Script Runner seems to be working inconsistently or not declaring variables correctly, then make sure Improved Console is updated to the latest version.
  • UDFs can not be defined in text files (Script Runner scripts), though they can be called. If they're under 512 characters long, lambdas can be used instead.

Sources

Eddoursul's JIP LN NVSE Script Runner Introduction