Jump to content

Recommended Posts

Hi...

There probably is a post on this somewhere else in the forum but I was wondering...

How do I make it so that a characters sanity will increase at night but decrease in the day?

I've looked in other places and tried the current characters (I'm also making a character that gains sanity from fire, so I took that out of Willow's code) but haven't found anything as yet.

But anyway, I could really use the help, Thank you.

-(FireBurns)Red

Link to comment
https://forums.kleientertainment.com/forums/topic/68271-night-sanity/
Share on other sites

local function sanityfn(inst)
	local light_delta = 0
	local lightval = inst.LightWatcher:GetLightValue()

	local day = GetClock():IsDay() and not GetWorld():IsCave()

	if day then
		-- Day gain, we make it same as night drain
		-- Day sanity is 0, so 0 plus drain equals drain
		light_delta = TUNING.SANITY_NIGHT_MID
	else
		local highval = TUNING.SANITY_HIGH_LIGHT
		local lowval = TUNING.SANITY_LOW_LIGHT

		if lightval > highval then
			-- Standing near a light source during the night
			-- Minus negative, so it's positive
			-- Make it double so it counteracts the drain and ends up positive
			light_delta = -TUNING.SANITY_NIGHT_LIGHT * 2
		elseif lightval < lowval then
			-- Total dark is still uncomfortable
			-- Make it a 0 so 0 plus heavy night drain is heavy night drain
			light_delta = 0
		else
			-- Standing in some light during the night
			-- Same as the first one, invert it and multiply it
			light_delta = -TUNING.SANITY_NIGHT_MID * 2
		end
	end

	return light_delta
end


inst.components.sanity.custom_rate_fn = sanityfn

 

Edited by DarkXero

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...