move checks to own function, and prevent guards from attacking guards
This commit is contained in:
parent
de63b259f7
commit
24ce3606ee
2 changed files with 53 additions and 30 deletions
9
.vscode/settings.json
vendored
Normal file
9
.vscode/settings.json
vendored
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
{
|
||||||
|
"Lua.diagnostics.globals": [
|
||||||
|
"mwscript",
|
||||||
|
"mwse",
|
||||||
|
"event",
|
||||||
|
"tes3",
|
||||||
|
"timer"
|
||||||
|
]
|
||||||
|
}
|
|
@ -16,19 +16,56 @@ local function isFriendlyActor(actor)
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
local function alertGuards(aggressor, cell)
|
local function doChecks(e)
|
||||||
-- a wanted player gets no help
|
if not config.combatEnable then
|
||||||
if tes3.mobilePlayer.bounty > 0 then
|
return false
|
||||||
log("Player is wanted, ignoring combat.")
|
|
||||||
return
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- if player initiates combat or combat is not against player, do nothing
|
||||||
|
if e.actor == tes3.mobilePlayer or e.target ~= tes3.mobilePlayer then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
-- inCombat is true after player has taken combat actions
|
||||||
|
-- or after combat has gone on awhile, but hopefully the guards will already be attacking by then
|
||||||
|
-- should be fine in cities, but will prevent players from provoking NPCs
|
||||||
|
-- in the wilderness and leading them into town
|
||||||
|
if tes3.mobilePlayer.inCombat then
|
||||||
|
log("Player is in combat, not sure who started it, so not helping.")
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
if config.ignored[e.actor.object.id] or config.ignored[e.actor.object.baseObject.id] then
|
||||||
|
log("Ignored NPC or creature detected, not helping.")
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
if isFriendlyActor(e.actor) then
|
||||||
|
log("Friendly actor, not helping.")
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
if tes3.mobilePlayer.bounty > 0 then
|
||||||
|
log("Player is wanted, ignoring combat.")
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
if e.actor.object.isGuard then
|
||||||
|
log("Guards don't fight guards!")
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
-- everything was good
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
local function alertGuards(aggressor, cell)
|
||||||
log("Checking for guards in cell %s to bring justice to %s", cell.name or cell.id, aggressor.object.name)
|
log("Checking for guards in cell %s to bring justice to %s", cell.name or cell.id, aggressor.object.name)
|
||||||
local playerPos = tes3.mobilePlayer.position
|
local playerPos = tes3.mobilePlayer.position
|
||||||
|
|
||||||
for npc in cell:iterateReferences(tes3.objectType.npc) do
|
for npc in cell:iterateReferences(tes3.objectType.npc) do
|
||||||
local distance = playerPos:distance(npc.position)
|
local distance = playerPos:distance(npc.position)
|
||||||
if npc.object.isGuard and distance <= config.combatDistance then
|
if npc.object.isGuard and npc.mobile and distance <= config.combatDistance then
|
||||||
log("Alerting %s, %s units away, to the combat!", npc.object.name, distance)
|
log("Alerting %s, %s units away, to the combat!", npc.object.name, distance)
|
||||||
|
|
||||||
if config.combatDialogue then
|
if config.combatDialogue then
|
||||||
|
@ -48,30 +85,7 @@ end
|
||||||
-- {{{ returned event functions
|
-- {{{ returned event functions
|
||||||
|
|
||||||
this.onCombatStarted = function(e)
|
this.onCombatStarted = function(e)
|
||||||
if not config.combatEnable then return end
|
if not doChecks(e) then return end
|
||||||
|
|
||||||
-- if player initiates combat or combat is not against player, do nothing
|
|
||||||
if e.actor == tes3.mobilePlayer or e.target ~= tes3.mobilePlayer then return end
|
|
||||||
|
|
||||||
-- inCombat is true after player has taken combat actions
|
|
||||||
-- or after combat has gone on awhile, but hopefully the guards will already be attacking by then
|
|
||||||
-- should be fine in cities, but will prevent players from provoking NPCs
|
|
||||||
-- in the wilderness and leading them into town
|
|
||||||
if tes3.mobilePlayer.inCombat then
|
|
||||||
log("Player is in combat, not sure who started it, so not helping.")
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
if config.ignored[e.actor.object.id] or config.ignored[e.actor.object.baseObject.id] then
|
|
||||||
log("Ignored NPC or creature detected, not helping.")
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
if isFriendlyActor(e.actor) then
|
|
||||||
log("Friendly actor, not helping.")
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
for _, cell in pairs(tes3.getActiveCells()) do
|
for _, cell in pairs(tes3.getActiveCells()) do
|
||||||
alertGuards(e.actor, cell)
|
alertGuards(e.actor, cell)
|
||||||
|
|
Loading…
Add table
Reference in a new issue