moved/disabled NPCs now really persist on load
This commit is contained in:
parent
d8499db3e3
commit
8a65a49b00
|
@ -13,7 +13,7 @@ local defaultConfig = {
|
||||||
showMessages = true,
|
showMessages = true,
|
||||||
-- npc settings
|
-- npc settings
|
||||||
disableNPCs = true,
|
disableNPCs = true,
|
||||||
moveNPCs = true,
|
moveNPCs = true, -- move NPCs to homes
|
||||||
keepBadWeatherNPCs = true,
|
keepBadWeatherNPCs = true,
|
||||||
-- classes and races that are ignored during inclement weather
|
-- classes and races that are ignored during inclement weather
|
||||||
badWeatherClassRace = {
|
badWeatherClassRace = {
|
||||||
|
@ -26,7 +26,7 @@ local defaultConfig = {
|
||||||
worstWeather = tes3.weather.thunder,
|
worstWeather = tes3.weather.thunder,
|
||||||
factionIgnorePercentage = 66,
|
factionIgnorePercentage = 66,
|
||||||
minimumOccupancy = 3,
|
minimumOccupancy = 3,
|
||||||
homelessWanderersToPublicHouses = false,
|
homelessWanderersToPublicHouses = false, -- move NPCs to public houses if they don't have a home
|
||||||
disableInteraction = true,
|
disableInteraction = true,
|
||||||
-- door settings
|
-- door settings
|
||||||
lockDoors = true,
|
lockDoors = true,
|
||||||
|
|
|
@ -23,7 +23,7 @@ end
|
||||||
-- very todd workaround
|
-- very todd workaround
|
||||||
local function getFightFromSpawnedReference(id)
|
local function getFightFromSpawnedReference(id)
|
||||||
-- Spawn a reference of the given id in toddtest
|
-- 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)
|
log(common.logLevels.medium, "[CHECKS] Spawning %s in %s", id, toddTest.id)
|
||||||
|
|
||||||
local ref = tes3.createReference({
|
local ref = tes3.createReference({
|
||||||
|
|
|
@ -16,8 +16,8 @@ this.createHomedNPCTableEntry = function(npc, home, startingPlace, isHome, posit
|
||||||
-- mod support for different positions in cells
|
-- mod support for different positions in cells
|
||||||
local id = common.checkModdedCell(home.id)
|
local id = common.checkModdedCell(home.id)
|
||||||
|
|
||||||
log(common.logLevels.medium, "[DTAB] Found %s for %s: %s... adding it to in memory table...",
|
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, id)
|
isHome and "home" or "public house", npc.object.name, startingPlace.id, id)
|
||||||
|
|
||||||
-- pick the position and orientation the NPC will be placed at
|
-- pick the position and orientation the NPC will be placed at
|
||||||
local pickedPosition, pickedOrientation, pos, ori
|
local pickedPosition, pickedOrientation, pos, ori
|
||||||
|
|
|
@ -64,8 +64,8 @@ end
|
||||||
local function putNPCsBack(npcData)
|
local function putNPCsBack(npcData)
|
||||||
for i = #npcData, 1, -1 do
|
for i = #npcData, 1, -1 do
|
||||||
local data = table.remove(npcData, i)
|
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,
|
log(common.logLevels.medium, "[PROC] Moving %s back outside to %s (%s, %s, %s)", data.npc.object.name,
|
||||||
data.ogPosition.x, data.ogPosition.y, data.ogPosition.z)
|
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
|
-- unset NPC data so we don't try to move them on load
|
||||||
data.npc.data.NPCsGoHome = nil
|
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)
|
log(common.logLevels.medium, "[PROC] Looking for moved NPCs in cell %s", cell.id)
|
||||||
for npc in cell:iterateReferences(tes3.objectType.npc) do
|
for npc in cell:iterateReferences(tes3.objectType.npc) do
|
||||||
if npc.data and npc.data.NPCsGoHome then
|
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
|
if npc.data.NPCsGoHome.disabled then
|
||||||
-- disabled NPC
|
-- disabled NPC
|
||||||
if checks.isBadWeatherNPC(npc) then
|
if badWeather then
|
||||||
common.runtimeData.disabledBadWeatherNPCs[npc.id] = npc
|
common.runtimeData.disabledBadWeatherNPCs[npc.id] = npc
|
||||||
-- table.insert(common.runtimeData.disabledBadWeatherNPCs, npc)
|
-- table.insert(common.runtimeData.disabledBadWeatherNPCs, npc)
|
||||||
else
|
else
|
||||||
|
@ -139,8 +141,17 @@ local function checkForMovedOrDisabledNPCs(cell)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
-- homed NPC
|
-- homed NPC
|
||||||
dataTables.createHomedNPCTableEntry(npc, cell, tes3.getCell(npc.data.NPCsGoHome.cell), true,
|
local homeData = dataTables.createHomedNPCTableEntry(npc, cell,
|
||||||
npc.data.NPCsGoHome.position, npc.data.NPCsGoHome.orientation)
|
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
|
end
|
||||||
end
|
end
|
||||||
|
@ -193,6 +204,7 @@ this.processNPCs = function(cell)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- LuaFormatter off
|
||||||
-- check for bad weather NPCs that have been disabled, and re-enable them
|
-- 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.movedBadWeatherNPCs) then putNPCsBack(common.runtimeData.movedBadWeatherNPCs) end
|
||||||
if not common.isEmptyTable(common.runtimeData.disabledBadWeatherNPCs) then reEnableNPCs(common.runtimeData.disabledBadWeatherNPCs) 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.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.disabledNPCs) then reEnableNPCs(common.runtimeData.disabledNPCs) end
|
||||||
if not common.isEmptyTable(common.runtimeData.disabledBadWeatherNPCs) then reEnableNPCs(common.runtimeData.disabledBadWeatherNPCs) end
|
if not common.isEmptyTable(common.runtimeData.disabledBadWeatherNPCs) then reEnableNPCs(common.runtimeData.disabledBadWeatherNPCs) end
|
||||||
|
-- LuaFormatter on
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -301,7 +314,8 @@ this.processDoors = function(cell)
|
||||||
tes3.setLockLevel({reference = door, level = 0})
|
tes3.setLockLevel({reference = door, level = 0})
|
||||||
tes3.unlock({reference = door})
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,7 @@ Forked from 1.1 of [OEA's Lightweight Lua Scheduling](https://www.nexusmods.com/
|
||||||
- NPC "homes"
|
- NPC "homes"
|
||||||
- Outside NPCs who have homes are currently paired with the inside cell of their home
|
- 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)
|
- Other NPCs are configurably paired with local public houses (Inns, temples, and guildhalls of their faction)
|
||||||
|
- Moved NPCs persist on save/load
|
||||||
|
|
||||||
## WIP ##
|
## 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
|
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
|
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
|
- 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 ##
|
## 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
|
- 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.
|
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
|
|
||||||
|
|
Loading…
Reference in a new issue