Jump to content

Recommended Posts

Depends on if you want it to be like +3/minute at say 50% health, or if you want it to go up by say 1 sanity for every 1 damage taken.

The former would want to use the custom sanity fn built into the sanity component to effect your current sanity rate, the latter would want to do a ListenForEvent for the healthdelta event pushed whenever your character takes damage of any kind.

On 3/1/2023 at 1:14 PM, Merkyrrie said:

Depends on if you want it to be like +3/minute at say 50% health, or if you want it to go up by say 1 sanity for every 1 damage taken.

The former would want to use the custom sanity fn built into the sanity component to effect your current sanity rate, the latter would want to do a ListenForEvent for the healthdelta event pushed whenever your character takes damage of any kind.

Oh, thank you! Sorry for checking late.
I want to regen sanity of 1/sec when my character's health is less than 50%!
What should I do in this case??

You can probably just use custom_rate_fn then,

-- In your master_postinit
inst.components.sanity.custom_rate_fn = myFunction

myFunction can be named whatever your function will be named, within the function you can do an if statement to check your current health's percentage with inst.components.health:GetPercent()

Then return the positive change to your sanity at the end of the function

local myFunction(inst)
	local delta = 0
	if inst.components.health:GetPercent() <= .5 then
  		delta = 1 -- This should be how much you want it to be recovering, I don't know the exact number to place here to get 1 sanity per second
  	end
	return delta
end

the returned value from custom_rate_fn is then directly added to the change whenever sanity is lowered overtime

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
×
  • Create New...