Jump to content

Lower the Sanity Drain at Night/Character Mod Help


Recommended Posts

Completely new to this whole modding etc thing, I am grasping the script concept pretty well, however, I am trying to do a simple task and not finding any answers. In short I want to change my character's sanity drain to a small amount during the day, less in the evening, and none at night. Any help is appreciated and remember, especially with scripting I am a novice!


Also if you know off hand if there is a way to make a character a little more comfortable in chilly weather, and also more uncomfortable in the heat to balance out, that would be just lovely! Thank you! :D

Link to comment
Share on other sites

Hi @LoganBerry, welcome to the forums!

You can set custom sanity values with dapperness, night_drain_mult and custom_rate_fn for the sanity component. dapperness in this case you might not need, it sets a flat sanity gain (or penalty) to your character at all times. Maxwell uses it. night_drain_mult affects time of day and light sources, I'd recommend you set it to 0 so your character isn't affected directly by this and instead handle it separately. Which is where custom_rate_fn comes in: it allows you to set a custom function to calculate (extra) sanity to your needs. For example, you could use this in your character lua file to handle time of day and temperature:

local function sanityfn(inst)
	local ret = (GetClock():IsDay() and -5)
		 or (GetClock():IsDusk() and -3)
		 or 0

	local temp = inst.components.temperature:GetCurrent()
	if temp > 50 then
		ret = ret + -(temp-50)/10
	elseif temp < 15 and temp > 0 then	--no sanity gain when freezing
		ret = ret + (15-temp)/5

	return ret

Then call it from your fn function:

local function fn(inst)
	-- other character stuff
	-- ...
	inst.components.sanity.night_drain_mult = 0
	inst.components.sanity.custom_rate_fn = sanityfn

Note that: I have not tested the code, so it could crash (unlikely, though); I made up the numbers, you'll want to make sure the values work for you (and I recommend you take a look at the scripts/components/sanity.lua file, specifically the Sanity:Recalc function); and I'm assuming RoG/SW, vanilla is very similar.

PS: you posted in the tutorials section. If you're looking for help with your mod, I suggest you post directly in the DS Modding section, or the DST Modding section if it's for DST.

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

  • Create New...