add basic interop module
allows getting/setting of global randomize chance, and overriding randomize chance of specific doors
This commit is contained in:
parent
4fb102d694
commit
d729bf0eed
3 changed files with 69 additions and 2 deletions
45
MWSE/mods/celediel/DoorRandomizer/interop.lua
Normal file
45
MWSE/mods/celediel/DoorRandomizer/interop.lua
Normal file
|
@ -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
|
|
@ -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)
|
||||
|
|
18
README.md
18
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)
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue