anAveragePerson Posted November 16, 2021 Share Posted November 16, 2021 Hey, since it is my first mod I wanted to keep it simple, but I ran into an issue. The idea is that my character should take a different amount of damage based on his sanity (high sanity - high defense/low sanity - low defense). However, inst.components.health.absorb does not seem to work with negative values. I am not sure if they are suitable for this kind of function, but I also tried to use inst.components.combat.externaldamagetakenmultiplier and inst.components.health:SetAbsorptionAmount (without success). I hope someone can help me. ^-^ local function calculateSanity(inst) local sanity = inst.components.sanity.current if inst:HasTag("playerghost") then return end if inst.components.health:IsDead() then return end if sanity >= 81 then inst.components.combat.damagemultiplier = 0.5 inst.components.health.absorb = 0.75 end if sanity <= 80 and sanity >= 61 then inst.components.combat.damagemultiplier = 0.75 inst.components.health.absorb = 0.5 end if sanity <= 60 and sanity >= 41 then inst.components.combat.damagemultiplier = 1 inst.components.health.absorb = 0.25 end if sanity <= 40 and sanity >= 21 then inst.components.combat.damagemultiplier = 1.25 inst.components.health.absorb = 0 end if sanity <= 20 and sanity >= 11 then inst.components.combat.damagemultiplier = 1.5 inst.components.health.absorb = -0.25 -- does not work end if sanity <= 10 and sanity >= 6 then inst.components.combat.damagemultiplier = 1.75 inst.components.health.absorb = -0.5 -- does not work end if sanity <= 5 and sanity >= 1 then inst.components.combat.damagemultiplier = 2 inst.components.health.absorb = -0.75 -- does not work end if sanity == 0 then inst.components.combat.damagemultiplier = 2.25 inst.components.health.absorb = -1 -- does not work end end Link to comment https://forums.kleientertainment.com/forums/topic/135348-taking-different-amount-of-damage-based-on-sanity/ Share on other sites More sharing options...
AkaiNight Posted November 16, 2021 Share Posted November 16, 2021 well im using this code for extra damage from hounds but im not sure how to change it as you like but im leaving it if u can local function ExtraHoundDamage(inst) local _GetAttacked = inst.components.combat.GetAttacked inst.components.combat.GetAttacked = function(self, attacker, damage, ...) if attacker and attacker:HasTag("hound") and damage then damage = damage * 1.5 end return _GetAttacked(self, attacker, damage, ...) end end ExtraHoundDamage(inst) master_postinit 1 Link to comment https://forums.kleientertainment.com/forums/topic/135348-taking-different-amount-of-damage-based-on-sanity/#findComment-1513618 Share on other sites More sharing options...
CarlZalph Posted November 16, 2021 Share Posted November 16, 2021 The combat component itself has two modify lists that are easily able to be modulated at your leisure without having to function hook. For your case, you will want to listen for the event "sanitydelta", and in the callback use the 'newpercent' field in the event data parameter. Since your sanity regions are pretty linear, it doesn't make too much sense to make them into their own bins rather than a linear interpolation. <player entity>.components.combat.externaldamagemultipliers:SetModifier(<any unique key>, <value>) <player entity>.components.combat.externaldamagetakenmultipliers:SetModifier(<any unique key>, <value>) Where <player entity> is the player instance of the sanity component, <any unique key> is something unique to your mod, and <value> is the interpolation value. To calculate out the interpolation value, you can do it manually or use one of Klei's functions defined in mathutil.lua. 'newpercent' is a value from [0, 1], and your values used here are in sanity units. So I can't tell you what sort of upper bound interpolation values to use. If your max sanity is above this 81 value, like I assume it is, then you can also create a curve such that the upper bound is clamped to 1.0 for all values above it. 1 1 Link to comment https://forums.kleientertainment.com/forums/topic/135348-taking-different-amount-of-damage-based-on-sanity/#findComment-1513625 Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now