Jump to content

How to Scale Character Damage with Sanity Loss


Recommended Posts

Hello, I need your help... So I would like when my character is fully sane, to deal .75 damage. And to scale to 2.25 when at 0 sanity. 

Since the function concept is similar to Wolfgang's hunger damage scaling, I tried looking at his code, but I'm too unfamiliar with coding language to figure it out.

sorry to ask for help but I was thinking this would be a good chance for me to learn. Any kind of help is appreciated.

thanks for reading :D

Link to comment
Share on other sites

31 minutes ago, Hurmyt said:

Since the function concept is similar to Wolfgang's hunger damage scaling, I tried looking at his code, but I'm too unfamiliar with coding language to figure it out.

In master_postinit of your character's file:

inst:ListenForEvent("sanitydelta", CalculateStrength)

And the function to put outside, on top on master_postinit:

local function CalculateStrength(inst, data)
	inst.components.combat.damagemultiplier = Remap(1 - data.newpercent, 0, 1, 0.75, 2.25)
end

Sanity changes push that delta event. It passes the new percent in a table, which we receive on data argument.

Remap remaps values from 0-1 to 0.75-2.25, so at percent 1 (full sanity), you remap 0, which returns 0.75.

At percent 0 (no sanity), you remap 1, which returns 2.25.

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
  • Create New...