option to ignore scripted doors

This commit is contained in:
Lilian Jónsdóttir 2020-08-08 14:21:20 -07:00
parent 9bce99b77b
commit 1ad59ef496
3 changed files with 63 additions and 35 deletions

View file

@ -6,6 +6,7 @@ local defaultConfig = {
wildernessCells = true,
needDoor = true,
keepRandomized = false,
ignoreScripted = true,
debug = false,
ignoredCells = {},
-- some of these aren't cell change doors but whatever

View file

@ -23,6 +23,35 @@ local function isTypeMatch(ogCell, chosenCell)
return ((ogCell.isInterior and ogCell.behavesAsExterior) or not ogCell.isInterior) ==
((chosenCell.isInterior and chosenCell.behavesAsExterior) or not chosenCell.isInterior)
end
local function doorCheck(door)
-- only randomize doors
if door.object.objectType ~= tes3.objectType.door then
return false
end
-- that trigger cell changes
if not door.destination then
return false
end
-- that aren't locked
if tes3.getLocked({reference = door}) then
return false
end
if config.ignoredDoors[string.lower(door.id)] then
log("Ignored door, not randomizing.")
return false
end
if config.ignoreScripted and door.object.script then
log("Scripted door, not randomizing.")
return false
end
return true
end
-- }}}
-- {{{ cell and position/orientation picking
@ -106,29 +135,8 @@ local function pickCellAndSpot(ogDest)
end
-- }}}
-- {{{ event functions
local function onActivate(e)
-- only do stuff on cell change doors
if e.activator ~= tes3.player and e.target.objectType ~= tes3.objectType.door then return end
local door = e.target
if config.ignoredDoors[string.lower(door.id)] then
log("Ignored door, not randomizing.")
return
end
-- don't randomize locked doors, or: only randomize when a cell change event happens
if door.destination and not tes3.getLocked({reference = door}) then
local roll = math.random(0, 100)
local rollStr = "Randomize Roll: %s "
if config.randomizeChance < roll then
log(rollStr .. "> %s, not randomizing", roll, config.randomizeChance)
return
end
log(rollStr .. "< %s, randomizing!", roll, config.randomizeChance)
-- {{{ the functions that do the thing
local function randomizeDoor(door)
log("Picking initial cell...")
local cell, spot = pickCellAndSpot(door.destination.cell)
@ -146,6 +154,23 @@ local function onActivate(e)
-- set the door's destination to the picked cell and position/orientation
tes3.setDestination({reference = door, cell = cell, position = spot.position, orientation = spot.orientation})
end
-- }}}
-- {{{ event functions
local function onActivate(e)
local door = e.target
-- 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
log("Randomize Roll: %s %s %s, %srandomizing!", roll,
randomize and "<" or ">", config.randomizeChance, randomize and "" or "not ")
if randomize then
randomizeDoor(door)
end
end
end

View file

@ -50,6 +50,8 @@ category:createYesNoButton({
variable = createTableVar("keepRandomized")
})
category:createYesNoButton({label = "Ignore scripted doors?", variable = createTableVar("ignoreScripted")})
category:createYesNoButton({label = "Debug logging", variable = createTableVar("debug")})
template:createExclusionsPage({