rebuild followers list on some dialogue options

This commit is contained in:
Lilian Jónsdóttir 2020-10-10 13:07:25 -07:00
parent c63ed5e4eb
commit c3a145a08b

View file

@ -9,8 +9,12 @@ local inspect = require("inspect")
-- {{{ variables and such -- {{{ variables and such
-- for rebuilding follower list on dialogue
local followMatches = {"follow", "together", "travel", "wait", "stay"}
-- timers -- timers
local updateTimer local updateTimer
local postDialogueTimer
-- }}} -- }}}
@ -97,6 +101,8 @@ local function updateCells()
end end
end end
-- todo: more robust trespass checking... maybe take faction and rank into account?
-- todo: maybe re-implement some or all features of Trespasser
local function updatePlayerTrespass(cell, previousCell) local function updatePlayerTrespass(cell, previousCell)
cell = cell or tes3.getPlayerCell() cell = cell or tes3.getPlayerCell()
@ -117,7 +123,9 @@ end
-- }}} -- }}}
-- {{{ event functions -- {{{ event functions
local function onActivated(e) local eventFunctions = {}
eventFunctions.onActivated = function(e)
if e.activator ~= tes3.player or e.target.object.objectType ~= tes3.objectType.npc or not config.disableInteraction then if e.activator ~= tes3.player or e.target.object.objectType ~= tes3.objectType.npc or not config.disableInteraction then
return return
end end
@ -133,7 +141,7 @@ local function onActivated(e)
end end
end end
local function onLoaded() eventFunctions.onLoaded = function()
tes3.player.data.NPCsGoHome = tes3.player.data.NPCsGoHome or {} tes3.player.data.NPCsGoHome = tes3.player.data.NPCsGoHome or {}
if tes3.player.cell then processors.searchCellsForNPCs() end if tes3.player.cell then processors.searchCellsForNPCs() end
@ -149,7 +157,7 @@ local function onLoaded()
end end
end end
local function onCellChanged(e) eventFunctions.onCellChanged = function(e)
updateCells() updateCells()
updatePlayerTrespass(e.cell, e.previousCell) updatePlayerTrespass(e.cell, e.previousCell)
checkEnteredNPCHome(e.cell) checkEnteredNPCHome(e.cell)
@ -158,8 +166,31 @@ local function onCellChanged(e)
end end
end end
eventFunctions.onInfoResponse = function(e)
-- the dialogue option clicked on
local dialogue = tostring(e.dialogue):lower()
-- what that dialogue option triggers; this will catch AIFollow commands
local command = e.command:lower()
for _, item in pairs(followMatches) do
if command:match(item) or dialogue:match(item) then
-- wait until game time restarts, and don't set multiple timers
if not postDialogueTimer or postDialogueTimer.state ~= timer.active then
log(common.logLevels.small, "Found %s in dialogue, rebuilding followers", item)
postDialogueTimer = timer.start({
type = timer.simulate,
duration = 0.25,
iteration = 1,
callback = function() common.runtimeData.followers = buildFollowerList() end
})
end
end
end
end
-- debug events -- debug events
local function onKeyDown(e) eventFunctions.onKeyDown = function(e)
if e.keyCode ~= tes3.scanCode.c then return end
-- if alt log runtimeData -- if alt log runtimeData
if e.isAltDown then if e.isAltDown then
-- ! this crashes my fully modded setup and I dunno why -- ! this crashes my fully modded setup and I dunno why
@ -173,7 +204,7 @@ local function onKeyDown(e)
local pos = tostring(tes3.player.position):gsub("%(", "{"):gsub("%)", "}") local pos = tostring(tes3.player.position):gsub("%(", "{"):gsub("%)", "}")
local ori = tostring(tes3.player.orientation):gsub("%(", "{"):gsub("%)", "}") local ori = tostring(tes3.player.orientation):gsub("%(", "{"):gsub("%)", "}")
log(common.logLevels.none, "[MAIN] {position = %s, orientation = %s},", pos, ori) log(common.logLevels.none, "[POSITIONS] {position = %s, orientation = %s},", pos, ori)
end end
end end
@ -183,12 +214,11 @@ end
local function onInitialized() local function onInitialized()
-- Register events -- Register events
log(common.logLevels.small, "[MAIN] Registering events...") log(common.logLevels.small, "[MAIN] Registering events...")
event.register("loaded", onLoaded) for name, func in pairs(eventFunctions) do
event.register("cellChanged", onCellChanged) local eventName = name:gsub("on(%u)", string.lower)
event.register("activate", onActivated) event.register(eventName, func)
log(common.logLevels.small, "[MAIN] %s event registered", eventName)
-- debug events end
event.register("keyDown", onKeyDown, { filter = tes3.scanCode.c } )
log(common.logLevels.none, "[MAIN] Successfully initialized") log(common.logLevels.none, "[MAIN] Successfully initialized")
end end