moved/disabled NPCs now really persist on load

This commit is contained in:
Lilian Jónsdóttir 2020-10-03 23:18:57 -07:00
parent d8499db3e3
commit 8a65a49b00
5 changed files with 27 additions and 18 deletions

View file

@ -13,7 +13,7 @@ local defaultConfig = {
showMessages = true,
-- npc settings
disableNPCs = true,
moveNPCs = true,
moveNPCs = true, -- move NPCs to homes
keepBadWeatherNPCs = true,
-- classes and races that are ignored during inclement weather
badWeatherClassRace = {
@ -26,7 +26,7 @@ local defaultConfig = {
worstWeather = tes3.weather.thunder,
factionIgnorePercentage = 66,
minimumOccupancy = 3,
homelessWanderersToPublicHouses = false,
homelessWanderersToPublicHouses = false, -- move NPCs to public houses if they don't have a home
disableInteraction = true,
-- door settings
lockDoors = true,

View file

@ -23,7 +23,7 @@ end
-- very todd workaround
local function getFightFromSpawnedReference(id)
-- Spawn a reference of the given id in toddtest
local toddTest = tes3.getCell("toddtest")
local toddTest = tes3.getCell({id = "toddtest"})
log(common.logLevels.medium, "[CHECKS] Spawning %s in %s", id, toddTest.id)
local ref = tes3.createReference({

View file

@ -16,8 +16,8 @@ this.createHomedNPCTableEntry = function(npc, home, startingPlace, isHome, posit
-- mod support for different positions in cells
local id = common.checkModdedCell(home.id)
log(common.logLevels.medium, "[DTAB] Found %s for %s: %s... adding it to in memory table...",
isHome and "home" or "public house", npc.object.name, id)
log(common.logLevels.medium, "[DTAB] Found %s for %s from %s: %s... adding it to in memory table...",
isHome and "home" or "public house", npc.object.name, startingPlace.id, id)
-- pick the position and orientation the NPC will be placed at
local pickedPosition, pickedOrientation, pos, ori

View file

@ -64,8 +64,8 @@ end
local function putNPCsBack(npcData)
for i = #npcData, 1, -1 do
local data = table.remove(npcData, i)
log(common.logLevels.medium, "[PROC] Moving %s back outside to %s (%s, %s, %s)", data.npc.object.name, data.ogPlace.id,
data.ogPosition.x, data.ogPosition.y, data.ogPosition.z)
log(common.logLevels.medium, "[PROC] Moving %s back outside to %s (%s, %s, %s)", data.npc.object.name,
data.ogPlace.id, data.ogPosition.x, data.ogPosition.y, data.ogPosition.z)
-- unset NPC data so we don't try to move them on load
data.npc.data.NPCsGoHome = nil
@ -127,10 +127,12 @@ local function checkForMovedOrDisabledNPCs(cell)
log(common.logLevels.medium, "[PROC] Looking for moved NPCs in cell %s", cell.id)
for npc in cell:iterateReferences(tes3.objectType.npc) do
if npc.data and npc.data.NPCsGoHome then
log(common.logLevels.large, "[PROC] %s has NPCsGoHome data, deciding if disabled or moved...%s", npc, json.encode(npc.data.NPCsGoHome))
log(common.logLevels.large, "[PROC] %s has NPCsGoHome data, deciding if disabled or moved...%s", npc,
json.encode(npc.data.NPCsGoHome))
local badWeather = checks.isBadWeatherNPC(npc)
if npc.data.NPCsGoHome.disabled then
-- disabled NPC
if checks.isBadWeatherNPC(npc) then
if badWeather then
common.runtimeData.disabledBadWeatherNPCs[npc.id] = npc
-- table.insert(common.runtimeData.disabledBadWeatherNPCs, npc)
else
@ -139,8 +141,17 @@ local function checkForMovedOrDisabledNPCs(cell)
end
else
-- homed NPC
dataTables.createHomedNPCTableEntry(npc, cell, tes3.getCell(npc.data.NPCsGoHome.cell), true,
npc.data.NPCsGoHome.position, npc.data.NPCsGoHome.orientation)
local homeData = dataTables.createHomedNPCTableEntry(npc, cell,
tes3.getCell({id = npc.data.NPCsGoHome.cell}),
true, npc.data.NPCsGoHome.position,
npc.data.NPCsGoHome.orientation)
-- add to in memory table
if badWeather then
table.insert(common.runtimeData.movedBadWeatherNPCs, homeData)
else
table.insert(common.runtimeData.movedNPCs, homeData)
end
end
end
end
@ -193,6 +204,7 @@ this.processNPCs = function(cell)
end
end
-- LuaFormatter off
-- check for bad weather NPCs that have been disabled, and re-enable them
if not common.isEmptyTable(common.runtimeData.movedBadWeatherNPCs) then putNPCsBack(common.runtimeData.movedBadWeatherNPCs) end
if not common.isEmptyTable(common.runtimeData.disabledBadWeatherNPCs) then reEnableNPCs(common.runtimeData.disabledBadWeatherNPCs) end
@ -209,6 +221,7 @@ this.processNPCs = function(cell)
if not common.isEmptyTable(common.runtimeData.movedBadWeatherNPCs) then putNPCsBack(common.runtimeData.movedBadWeatherNPCs) end
if not common.isEmptyTable(common.runtimeData.disabledNPCs) then reEnableNPCs(common.runtimeData.disabledNPCs) end
if not common.isEmptyTable(common.runtimeData.disabledBadWeatherNPCs) then reEnableNPCs(common.runtimeData.disabledBadWeatherNPCs) end
-- LuaFormatter on
end
end
@ -301,7 +314,8 @@ this.processDoors = function(cell)
tes3.setLockLevel({reference = door, level = 0})
tes3.unlock({reference = door})
log(common.logLevels.medium, "[PROC] unlocking: %s to %s", door.object.name, door.destination.cell.id)
log(common.logLevels.medium, "[PROC] unlocking: %s to %s", door.object.name,
door.destination.cell.id)
end
end

View file

@ -18,6 +18,7 @@ Forked from 1.1 of [OEA's Lightweight Lua Scheduling](https://www.nexusmods.com/
- NPC "homes"
- Outside NPCs who have homes are currently paired with the inside cell of their home
- Other NPCs are configurably paired with local public houses (Inns, temples, and guildhalls of their faction)
- Moved NPCs persist on save/load
## WIP ##
@ -29,10 +30,6 @@ Forked from 1.1 of [OEA's Lightweight Lua Scheduling](https://www.nexusmods.com/
gold and if a merchant with a cell, the worth of items in containers in that
cell that the NPC sells is added, and the total of all calculated values
- Public houses are classed based on the worth of NPCs in the cell
- Moved NPCs persist on save/load
- works if the game is still running when the save is loaded
- if the game is launched fresh, and a save with moved/disabled NPCs is loaded, it's still broken
- ? WHY ?
## TODO ##
@ -43,5 +40,3 @@ Forked from 1.1 of [OEA's Lightweight Lua Scheduling](https://www.nexusmods.com/
- If NPCs in a town are moved, and the player moves far away from that town before they're moved back, then
saves and reloads, those NPCs will probably stay moved.
- Launching the game and loading a save with moved/disabled NPCs, they won't be put back/enabled.
- send help