option to stop combat between friends; somecleanup
This commit is contained in:
parent
257e3e94fb
commit
1b56ace191
|
@ -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, ignored = {}}
|
local defaultConfig = {stopDamage = true, stopCombat = true, debug = false, ignored = {}}
|
||||||
local this = {}
|
local this = {}
|
||||||
|
|
||||||
this.getConfig = function()
|
this.getConfig = function()
|
||||||
|
|
|
@ -13,38 +13,23 @@ 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)
|
-- {{{ internal functions
|
||||||
|
local function notActuallyFriend(friend)
|
||||||
if not friend then return false end
|
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
|
local obj = friend.baseObject and friend.baseObject or
|
||||||
(friend.object.baseObject and friend.object.baseObject or friend.object)
|
(friend.object.baseObject and friend.object.baseObject or friend.object)
|
||||||
|
|
||||||
-- ignored More Attentive Guards followers
|
|
||||||
local magGuard = mag and mag.getGuardFollower() or nil
|
local magGuard = mag and mag.getGuardFollower() or nil
|
||||||
if friend == magGuard then
|
local ignoredId = config.ignored[obj.id:lower()]
|
||||||
log("Ignored MAG Guard %s", obj.name)
|
local ignoredMod = config.ignored[obj.sourceMod:lower()]
|
||||||
return false
|
|
||||||
end
|
|
||||||
|
|
||||||
-- ignored id
|
log("Friend %s: Is MAG Guard:%s, Ignored id:%s, Ignored mod:%s", obj.name, friend == magGuard,
|
||||||
if config.ignored[obj.id:lower()] then
|
ignoredId or "false", ignoredMod or "false")
|
||||||
log("Ignored id %s", obj.id)
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
|
|
||||||
-- ignored mod
|
return friend == magGuard or ignoredId or ignoredMod
|
||||||
if config.ignored[obj.sourceMod:lower()] then
|
|
||||||
log("Ignored mod %s", obj.sourceMod)
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
|
|
||||||
-- otherwise,
|
|
||||||
return true
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local function followerDamageCheck(attacker, attackee)
|
local function followerCheck(attacker, target)
|
||||||
return followers[attacker.object.id] ~= nil and followers[attackee.object.id] ~= nil and attacker ~= attackee
|
return followers[attacker.object.id] ~= nil and followers[target.object.id] ~= nil and attacker ~= target
|
||||||
end
|
end
|
||||||
|
|
||||||
local function buildFollowerList()
|
local function buildFollowerList()
|
||||||
|
@ -53,7 +38,8 @@ local function buildFollowerList()
|
||||||
local msg = ""
|
local msg = ""
|
||||||
|
|
||||||
for friend in tes3.iterate(tes3.mobilePlayer.friendlyActors) do
|
for friend in tes3.iterate(tes3.mobilePlayer.friendlyActors) do
|
||||||
if friendCheck(friend) then
|
-- nice double negative
|
||||||
|
if not notActuallyFriend(friend) then
|
||||||
friends[friend.object.id] = true
|
friends[friend.object.id] = true
|
||||||
msg = msg .. friend.object.name .. " "
|
msg = msg .. friend.object.name .. " "
|
||||||
end
|
end
|
||||||
|
@ -61,15 +47,17 @@ local function buildFollowerList()
|
||||||
if msg ~= "" then log("Friends: %s", msg) end
|
if msg ~= "" then log("Friends: %s", msg) end
|
||||||
return friends
|
return friends
|
||||||
end
|
end
|
||||||
|
-- }}}
|
||||||
|
|
||||||
-- Event functions
|
-- {{{ Event functions
|
||||||
local eventFunctions = {}
|
local eventFunctions = {}
|
||||||
|
|
||||||
|
-- {{{ events to actually do the stuff
|
||||||
eventFunctions.onDamage = function(e)
|
eventFunctions.onDamage = function(e)
|
||||||
if not e.attackerReference then return end
|
if not e.attackerReference then return end
|
||||||
|
|
||||||
if followerDamageCheck(e.attackerReference, e.reference) then
|
if followerCheck(e.attackerReference, e.reference) then
|
||||||
if config.enable then
|
if config.stopDamage 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)
|
||||||
e.damage = 0
|
e.damage = 0
|
||||||
|
@ -77,12 +65,22 @@ eventFunctions.onDamage = function(e)
|
||||||
else
|
else
|
||||||
log("%s hit %s for %s friendly damage", e.attackerReference.object.name, e.reference.object.name, e.damage)
|
log("%s hit %s for %s friendly damage", e.attackerReference.object.name, e.reference.object.name, e.damage)
|
||||||
end
|
end
|
||||||
-- uncomment this to see all damage done by everyone to everyone else
|
-- uncomment this to see all damage done by everyone to everyone else
|
||||||
-- else
|
-- else
|
||||||
-- log("%s hit %s for %s damage", e.attackerReference.object.name, e.reference.object.name, e.damage)
|
-- log("%s hit %s for %s damage", e.attackerReference.object.name, e.reference.object.name, e.damage)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- prevent combat from even happening between friendly actors
|
||||||
|
eventFunctions.onCombatStart = function(e)
|
||||||
|
if config.stopCombat and followerCheck(e.actor, e.target) then
|
||||||
|
log("Friendly combat attempted, putting a stop to it!")
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
-- }}}
|
||||||
|
|
||||||
|
-- {{{ events to rebuild follower list
|
||||||
eventFunctions.onCellChanged = function(e) followers = buildFollowerList() end
|
eventFunctions.onCellChanged = function(e) followers = buildFollowerList() end
|
||||||
|
|
||||||
-- hopefully, when telling a follower to follow or wait, rebuild followers list
|
-- hopefully, when telling a follower to follow or wait, rebuild followers list
|
||||||
|
@ -122,6 +120,8 @@ eventFunctions.onSpellCasted = function(e)
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
-- }}}
|
||||||
|
-- }}}
|
||||||
|
|
||||||
-- Register events
|
-- Register events
|
||||||
local function onInitialized()
|
local function onInitialized()
|
||||||
|
|
|
@ -12,8 +12,13 @@ local page = template:createSideBarPage({
|
||||||
local category = page:createCategory(common.modName)
|
local category = page:createCategory(common.modName)
|
||||||
|
|
||||||
category:createYesNoButton({
|
category:createYesNoButton({
|
||||||
label = "Stop friendly fire",
|
label = "Stop friendly damage",
|
||||||
variable = mwse.mcm.createTableVariable({id = "enable", table = config})
|
variable = mwse.mcm.createTableVariable({id = "stopDamage", table = config})
|
||||||
|
})
|
||||||
|
|
||||||
|
category:createYesNoButton({
|
||||||
|
label = "Stop friendly combat from occurring",
|
||||||
|
variable = mwse.mcm.createTableVariable({id = "stopCombat", table = config})
|
||||||
})
|
})
|
||||||
|
|
||||||
category:createYesNoButton({
|
category:createYesNoButton({
|
||||||
|
|
Loading…
Reference in a new issue