build follower list on load, cellchange and timer

This commit is contained in:
Lilian Jónsdóttir 2020-08-17 00:07:37 -07:00
parent f15e923104
commit f5dd86dc9c

View file

@ -103,6 +103,18 @@ local function getFightFromSpawnedReference(id)
return fight return fight
end end
local function buildFollowerList()
local f = {}
-- build our followers list
for friend in tes3.iterate(tes3.mobilePlayer.friendlyActors) do
if friend ~= tes3.player then -- ? why is the player friendly towards the player ?
f[friend.object.id] = true
log(common.logLevels.large, "%s is follower", friend.object.id)
end
end
return f
end
-- {{{ npc evaluators -- {{{ npc evaluators
-- NPCs barter gold + value of all inventory items -- NPCs barter gold + value of all inventory items
@ -856,16 +868,6 @@ end
local function applyChanges(cell) local function applyChanges(cell)
if not cell then cell = tes3.getPlayerCell() end if not cell then cell = tes3.getPlayerCell() end
-- build our followers list
for friend in tes3.iterate(tes3.mobilePlayer.friendlyActors) do
local obj = friend.baseObject and friend.baseObject or friend.object
if friend ~= tes3.mobilePlayer then
followers[obj.id] = true
-- log(common.logLevels.large, "%s is follower", obj.id)
end
end
if isIgnoredCell(cell) then return end if isIgnoredCell(cell) then return end
-- Interior cell, except Canton cells, don't do anything -- Interior cell, except Canton cells, don't do anything
@ -886,6 +888,8 @@ end
local function updateCells() local function updateCells()
log(common.logLevels.medium, "Updating active cells!") log(common.logLevels.medium, "Updating active cells!")
followers = buildFollowerList()
for _, cell in pairs(tes3.getActiveCells()) do for _, cell in pairs(tes3.getActiveCells()) do
log(common.logLevels.large, "Applying changes to cell %s", cell.id) log(common.logLevels.large, "Applying changes to cell %s", cell.id)
applyChanges(cell) applyChanges(cell)
@ -929,6 +933,8 @@ local function onLoaded()
-- movedNPCs = tes3.player.data.NPCsGoHome.movedNPCs or {} -- movedNPCs = tes3.player.data.NPCsGoHome.movedNPCs or {}
if tes3.player.cell then searchCellsForNPCs() end if tes3.player.cell then searchCellsForNPCs() end
followers = buildFollowerList()
if not updateTimer or (updateTimer and updateTimer.state ~= timer.active) then if not updateTimer or (updateTimer and updateTimer.state ~= timer.active) then
updateTimer = timer.start({ updateTimer = timer.start({
type = timer.simulate, type = timer.simulate,
@ -941,6 +947,7 @@ end
local function onCellChanged(e) local function onCellChanged(e)
updateCells() updateCells()
followers = buildFollowerList()
updatePlayerTrespass(e.cell, e.previousCell) updatePlayerTrespass(e.cell, e.previousCell)
checkEnteredNPCHome(e.cell) checkEnteredNPCHome(e.cell)
if e.cell.name then -- exterior wilderness cells don't have name if e.cell.name then -- exterior wilderness cells don't have name