diff --git a/MWSE/mods/celediel/DoorRandomizer/interop.lua b/MWSE/mods/celediel/DoorRandomizer/interop.lua new file mode 100644 index 0000000..aecad9e --- /dev/null +++ b/MWSE/mods/celediel/DoorRandomizer/interop.lua @@ -0,0 +1,45 @@ +local common = require("celediel.DoorRandomizer.common") +local config = require("celediel.DoorRandomizer.config").getConfig() + +local this = {} + +-- {{{ randomize specific doors +this.randomizeDoor = function(door, chance) + if not door.object or door.object.objectType ~= tes3.objectType.door then + common.log("[Interop] Only doors can be randomized, ya goof.") + return + end + + chance = chance or 0 + + if not door.data.doorRandomizer then door.data.doorRandomizer = {} end + + door.data.doorRandomizer.randomizeChance = chance +end + +this.unRandomizeDoor = function(door) + if not door.object or door.object.objectType ~= tes3.objectType.door then + common.log("[Interop] Only doors can be unrandomized, ya goof.") + return + end + + door.data.doorRandomizer = nil +end +-- }}} + +-- {{{ global randomize chance +this.setRandomizeChance = function(chance) + if not chance or type(chance) ~= "number" then + common.log("[Interop] Randomize chance must be a number, ya goof.") + return + end + + config.randomizeChance = chance +end + +this.getRandomizeChance = function() + return config.randomizeChance +end +-- }}} + +return this diff --git a/MWSE/mods/celediel/DoorRandomizer/main.lua b/MWSE/mods/celediel/DoorRandomizer/main.lua index 66d61e7..9a7f23e 100644 --- a/MWSE/mods/celediel/DoorRandomizer/main.lua +++ b/MWSE/mods/celediel/DoorRandomizer/main.lua @@ -163,10 +163,14 @@ local function onActivate(e) -- only randomize good doors that the player activates if e.activator == tes3.player and doorCheck(door) then local roll = math.random(1, 100) - local randomize = config.randomizeChance > roll + + -- door overrides from interop + local chance = door.data.doorRandomizer and door.data.doorRandomizer.randomizeChance or config.randomizeChance + + local randomize = chance > roll log("Randomize Roll: %s %s %s, %srandomizing!", roll, - randomize and "<" or ">", config.randomizeChance, randomize and "" or "not ") + randomize and "<" or ">", chance, randomize and "" or "not ") if randomize then randomizeDoor(door) diff --git a/README.md b/README.md index d7b2f82..56d8a71 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,24 @@ the cell is chosen randomly from that list. If none are found, a default of * Ignore list for doors * Debug logging, to see my cool recursive functions at work +## Interop Module ## + +For modders, an interop module is included. Use it like so: + +```Lua + +local interop = require("celediel.DoorRandomizer.interop") -- the module + +local chance = interop.getRandomizeChance() -- get global randomize chance +interop.setRandomizeChance(chance + 25) -- set global randomize chance + +-- https://mwse.readthedocs.io/en/latest/lua/type/tes3door.html +local door -- a tes3door references + +interop.randomizeDoor(door, 100) -- overrides randomize chance for this one door +interop.unRandomizeDoor(door) -- removes overrides +``` + ## Requirements ## MWSE 2.1 nightly @ [github](https://github.com/MWSE/MWSE)