add ignore list; fix nullifying self damage
This commit is contained in:
parent
b576864f31
commit
2af019b098
|
@ -6,6 +6,6 @@ this.modConfig = this.modName:gsub("%s", "")
|
||||||
this.modInfo = "Stop friendly fire. Player companions can't damage the player, the player " ..
|
this.modInfo = "Stop friendly fire. Player companions can't damage the player, the player " ..
|
||||||
"can't damage companions, and companions can't damage each other. That's it."
|
"can't damage companions, and companions can't damage each other. That's it."
|
||||||
this.author = "Celediel"
|
this.author = "Celediel"
|
||||||
this.version = "1.2.1"
|
this.version = "1.3.0"
|
||||||
|
|
||||||
return this
|
return this
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
local common = require("celediel.NoMoreFriendlyFire.common")
|
local common = require("celediel.NoMoreFriendlyFire.common")
|
||||||
|
|
||||||
local currentConfig
|
local currentConfig
|
||||||
local defaultConfig = {enable = true, debug = false}
|
local defaultConfig = {enable = true, debug = false, ignored = {}}
|
||||||
local this = {}
|
local this = {}
|
||||||
|
|
||||||
this.getConfig = function()
|
this.getConfig = function()
|
||||||
|
|
|
@ -2,9 +2,7 @@ local common = require("celediel.NoMoreFriendlyFire.common")
|
||||||
local config = require("celediel.NoMoreFriendlyFire.config").getConfig()
|
local config = require("celediel.NoMoreFriendlyFire.config").getConfig()
|
||||||
|
|
||||||
local mag
|
local mag
|
||||||
pcall(function()
|
pcall(function() mag = require("celediel.MoreAttentiveGuards.interop") end)
|
||||||
mag = require("celediel.MoreAttentiveGuards.interop")
|
|
||||||
end)
|
|
||||||
|
|
||||||
-- todo: make this not hardcoded somehow
|
-- todo: make this not hardcoded somehow
|
||||||
local followMatches = {"follow", "together", "travel", "wait", "stay"}
|
local followMatches = {"follow", "together", "travel", "wait", "stay"}
|
||||||
|
@ -15,19 +13,52 @@ local function log(...) if config.debug then mwse.log("[%s] %s", common.modName,
|
||||||
-- keep track of followers
|
-- keep track of followers
|
||||||
local followers = {}
|
local followers = {}
|
||||||
|
|
||||||
|
local function friendCheck(friend)
|
||||||
|
if not friend then return false end
|
||||||
|
|
||||||
|
-- first try baseObject, then try object.baseObject, finally settle on object
|
||||||
|
local obj = friend.baseObject and friend.baseObject or
|
||||||
|
(friend.object.baseObject and friend.object.baseObject or friend.object)
|
||||||
|
|
||||||
|
-- ignored More Attentive Guards followers
|
||||||
|
local magGuard = mag and mag.getGuardFollower() or nil
|
||||||
|
if friend == magGuard then
|
||||||
|
log("Ignored MAG Guard %s", obj.name)
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
-- ignored id
|
||||||
|
if config.ignored[obj.id:lower()] then
|
||||||
|
log("Ignored id %s", obj.id)
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
-- ignored mod
|
||||||
|
if config.ignored[obj.sourceMod:lower()] then
|
||||||
|
log("Ignored mod %s", obj.sourceMod)
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
-- otherwise,
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
local function followerDamageCheck(attacker, attackee)
|
||||||
|
return followers[attacker.object.id] ~= nil and followers[attackee.object.id] ~= nil and attacker ~= attackee
|
||||||
|
end
|
||||||
|
|
||||||
local function buildFollowerList()
|
local function buildFollowerList()
|
||||||
local friends = {}
|
local friends = {}
|
||||||
|
|
||||||
local msg = ""
|
local msg = ""
|
||||||
local magGuard = mag and mag.getGuardFollower() or nil
|
|
||||||
|
|
||||||
for friend in tes3.iterate(tes3.mobilePlayer.friendlyActors) do
|
for friend in tes3.iterate(tes3.mobilePlayer.friendlyActors) do
|
||||||
if friend ~= magGuard then
|
if friendCheck(friend) then
|
||||||
friends[friend.object.id] = true
|
friends[friend.object.id] = true
|
||||||
msg = msg .. friend.object.name .. " "
|
msg = msg .. friend.object.name .. " "
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
log("Friends: %s", msg)
|
if msg ~= "" then log("Friends: %s", msg) end
|
||||||
return friends
|
return friends
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -37,7 +68,7 @@ local eventFunctions = {}
|
||||||
eventFunctions.onDamage = function(e)
|
eventFunctions.onDamage = function(e)
|
||||||
if not e.attackerReference then return end
|
if not e.attackerReference then return end
|
||||||
|
|
||||||
if followers[e.attackerReference.object.id] and followers[e.reference.object.id] then
|
if followerDamageCheck(e.attackerReference, e.reference) then
|
||||||
if config.enable then
|
if config.enable then
|
||||||
log("%s hit %s for %s friendly damage, nullifying", e.attackerReference.object.name,
|
log("%s hit %s for %s friendly damage, nullifying", e.attackerReference.object.name,
|
||||||
e.reference.object.name, e.damage)
|
e.reference.object.name, e.damage)
|
||||||
|
@ -70,9 +101,7 @@ eventFunctions.onInfoResponse = function(e)
|
||||||
type = timer.simulate,
|
type = timer.simulate,
|
||||||
duration = 0.5,
|
duration = 0.5,
|
||||||
iteration = 1,
|
iteration = 1,
|
||||||
callback = function()
|
callback = function() followers = buildFollowerList() end
|
||||||
followers = buildFollowerList()
|
|
||||||
end
|
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -21,4 +21,16 @@ category:createYesNoButton({
|
||||||
variable = mwse.mcm.createTableVariable({id = "debug", table = config})
|
variable = mwse.mcm.createTableVariable({id = "debug", table = config})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
template:createExclusionsPage({
|
||||||
|
label = "Ignored things",
|
||||||
|
description = "NPCs, creatures, and anything from plugins on this list won't be counted as a follower.",
|
||||||
|
showAllBlocked = false,
|
||||||
|
filters = {
|
||||||
|
{label = "Plugins", type = "Plugin"},
|
||||||
|
{label = "NPCs", type = "Object", objectType = tes3.objectType.npc},
|
||||||
|
{label = "Creatures", type = "Object", objectType = tes3.objectType.creature}
|
||||||
|
},
|
||||||
|
variable = mwse.mcm.createTableVariable({id = "ignored", table = config})
|
||||||
|
})
|
||||||
|
|
||||||
return template
|
return template
|
||||||
|
|
Loading…
Reference in a new issue