Morrowind
0 of 0

File information

Last updated

Original upload

Created by

GOOGLEPOX

Uploaded by

GOOGLEPOX

Virus scan

Safe to use

Tags for this mod

About this mod

Framework for loading config files to dynamically replace objects at runtime. No lua knowledge required!

Requirements
Permissions and credits
Changelogs
MWSE Dynamic Object Replacer

Inspired by powerOfThree's amazing Base Object Swapper for Skyrim, this mod adds a (fairly simple) MWSE framework for loading config files to dynamically replace object references at runtime. No lua coding knowledge is required! 

As of 1.1.0, the old way of loading config files still works, but there is an additional API included for your own lua mods.

Requirements
  • MWSE

Details
Config files go into Data Files/MWSE/mods/_OR_/ and require a specific format (we'll get to that later!). On startup, this mod loads all config files and merges any conflicting entries.

As of 1.1.0, you can now simply include the DOR library in your lua mods as an additional way to load config files. 

-- simply place something like this in your lua file

local objectReplacer = require("DOR.GPObjectReplacer")

-- and then call objectReplacer.loadORFile(filepath) to load your config file (can be located anywhere and named anything)

objectReplacer.loadORFile(yourConfigFilePathHere)

That's it!


Then every time an object is loaded (referenceActivated) this mod checks for objects to replace and calculates the chances (if given) accordingly. The mod doesn't actually replace the base object of the reference, but simply creates a new reference with the same scale, position, and orientation and disables the old one. Therefore, it is best to replace objects with similar mesh structures.

File Structure
To get started, simply create a file in Data Files/MWSE/mods/_OR_/ and call it whatever you like, as long as the file name starts with _OR_. I would recommend naming it like so _OR_YourModName.lua

Note that the _OR_ prefix and .lua extension are required. (Unless you are loading a config file through your own lua mod)

Here is an example of such a file for replacing gold coins with different coins (for an upcoming mod of mine) comments are added for clarity. 

IMPORTANT: You must structure your file identically to this example, including naming convention

_OR_GPBank.lua
objectsToReplace = {
    objectToReplace0 = {
oldObject = "Gold_001",
newObjects = {
newObject0 = {
newObject = "GPBankSeptimSilver",
replaceChance = 0.25,
excludedCell = {
{cellName = "Addamasartus"},
},
},
newObject1 = {
newObject = "GPBankSeptimGold",
replaceChance = 0.05,
}
}
},
objectToReplace1 = {
oldObject = "Gold_005",
newObjects = {
newObject0 = {
newObject = "GPBankSeptimSilver_005",
replaceChance = 0.10,
},
newObject1 = {
newObject = "GPBankSeptimGold_005",
replaceChance = 1,
specificCell = {
{cellName = "house"},
},
}
}
},
}
return objectsToReplace

objectsToReplace - The root object of a mod's config file. Contains all other objects
----objectToReplaceX - A series of structures inside the root object, each representing a unique base object to replace
--------oldObject - The object you want to replace. The value should be the string ID of the base object.
--------newObjects - A structure containing possible replacer objects
------------newObjectX - An object representing a possible replacer object
----------------newObject - A possible replacer object. The value should be the string ID of the replacer object.
----------------replaceChance - The chance from 0 to 1 as a float that this newObject will replace the listed oldObject. If this is not declared, will default to 1 (100%)
----------------excludedCell - A structure of individual table objects, each with a single field cellName. The name can be an exact cell name or a string pattern to search for. In this example, the replacer will be considered in all cells except Addamasartus.
----------------specificCell - A structure of individual table objects, each with a single field cellName. Like excludedCell, the name can be an exact cell name or a string pattern to search for. In this example, the replacer will be considered only in cells that contain the substring "house".

Don't worry about capitalization in these names, the check capitalizes both strings and then compares. Do, however, be wary of excess punctuation and whitespace.

My code is also documented if you want to take a look at the internal logic.


Prioritizing Entries
Should you have multiple entries for a single base object this mod will sort them like so:
  • Entries with a specific cell specified are calculated before all others in that cell
  • Entries with a higher chance are calculated before entries with a lower chance
  • If two entries have the same specific cell specified, will calculate the one with higher chance
  • If two entries have the same chance, will calculate whichever comes first alphabetically

Future Plans

Continued support and additional features such as more conditions for swapping.

Keep an eye open for my upcoming currency mod!

Credits
NullCascade and co for MWSE
Bethesda for Morrowind