Jump to content

Preventing Sanity Loss from Wetness


Recommended Posts

Hello all. I'm making a character mod for Don't Starve Together and I would like for this character's Sanity to be unaffected by Wetness. According to the wiki, Sanity loss from Wetness comes from "worn items draining Sanity" when the Wetness meter reaches 35. As I understand it, therefore, Rain and Wetness in and of themselves do not cause Sanity Drain - rather, a sanity drain feature is triggered to run when a threshold is met.

To be clear: what I would like for this character isn't to stop rain from happening. Nor do I want to stop Wetness from being applied to my character or his inventory. I'm fine with items becoming slippery, etc., when Wetness is applied. All I want is to stop Sanity drain from Wetness from being applied to my character. Meanwhile any other characters should, naturally, still receive Wetness and Sanity Drain as usual.

Preferably I'd like to stop the sanity drain feature from being activated in the first place - IF it is actually the case that this is a simple feature one can find a trigger for, and then stop that trigger from running.

Alternatively, I was thinking about perhaps telling the game to trigger a sanity gain equal to the sanity drain, to start running whenever the sanity drain feature is triggered, and to stop running whenever the sanity drain feature stops running.

I've found one other thread that dealt with Sanity gain during Rain, but it had only one reply with a bit of (at least to me) strangely formatted code and very little info, and I'm not confident I have gleaned all the right information from it.

Therefore, is there anyone who knows a bit about Rain, Wetness and Sanity and might be able to give me some explanation and help in this regard? It would be greatly appreciated.

Link to comment
Share on other sites

2 hours ago, Lucidaxe said:

Preferably I'd like to stop the sanity drain feature from being activated in the first place - IF it is actually the case that this is a simple feature one can find a trigger for, and then stop that trigger from running.

No such trigger.

2 hours ago, Lucidaxe said:

Alternatively, I was thinking about perhaps telling the game to trigger a sanity gain equal to the sanity drain, to start running whenever the sanity drain feature is triggered, and to stop running whenever the sanity drain feature stops running.

Now that's more feasible.

local easing = require("easing")

local function NoWetnessRate(inst)
	local moist_dapperness = 0
	for k, v in pairs(inst.components.inventory.equipslots) do
		if v:GetIsWet() and v.components.equippable then
			moist_dapperness = moist_dapperness - TUNING.WET_ITEM_DAPPERNESS
		end
	end
	local moisture = inst.components.moisture
	local moisture_delta = easing.inSine(moisture:GetMoisture(), 0, TUNING.MOISTURE_SANITY_PENALTY_MAX, moisture:GetMaxMoisture())
	return moist_dapperness - moisture_delta
end

in the body of your character's lua prefab file, with

inst.components.sanity.custom_rate_fn = NoWetnessRate

inside the master_postinit function of your character.

Basically, on each tick the game calculates your sanity debuff for wetness, and gives you the option to use a custom rate function so you can input your own delta to the rate. Then you calculate the same wetness debuff, and use it to counteract the effects.

As such, you can carry a soaked backpack with no sanity penalty, and you can stay at 100 wetness with no sanity penalty.

Link to comment
Share on other sites

That's very interesting, thanks for the coding and explanation. I have just one question. Suppose under the master_postinit function of my character, I'd simply put:

inst.components.sanity.moisture_delta = 0

In my admittedly simplistic mind, this would mean that in the calculation of sanity for the character, moisture would no longer add or subtract to the equation that makes up the calculation, but... I suppose it wouldn't be quite that simple? What would happen if I did that?

Link to comment
Share on other sites

3 minutes ago, Lucidaxe said:

That's very interesting, thanks for the coding and explanation. I have just one question. Suppose under the master_postinit function of my character, I'd simply put:

inst.components.sanity.moisture_delta = 0

In my admittedly simplistic mind, this would mean that in the calculation of sanity for the character, moisture would no longer add or subtract to the equation that makes up the calculation, but... I suppose it wouldn't be quite that simple? What would happen if I did that?

It would just get overwritten when the sanity component calculates the delta again, in line 271:

local moisture_delta = easing.inSine(self.inst.components.moisture:GetMoisture(), 0, TUNING.MOISTURE_SANITY_PENALTY_MAX, self.inst.components.moisture:GetMaxMoisture())

 

Link to comment
Share on other sites

2 minutes ago, DrSmugleaf said:

It would just get overwritten when the sanity component calculates the delta again, in line 271:


local moisture_delta = easing.inSine(self.inst.components.moisture:GetMoisture(), 0, TUNING.MOISTURE_SANITY_PENALTY_MAX, self.inst.components.moisture:GetMaxMoisture())

 

I see. Figured it was too simple. Thanks for your help :)

Link to comment
Share on other sites

23 minutes ago, DrSmugleaf said:

It would just get overwritten when the sanity component calculates the delta again, in line 271:


local moisture_delta = easing.inSine(self.inst.components.moisture:GetMoisture(), 0, TUNING.MOISTURE_SANITY_PENALTY_MAX, self.inst.components.moisture:GetMaxMoisture())

 

On second thought, would it also be possible to edit TUNING.MOISTURE_SANITY_PENALTY_MAX to set a zero sanity drain rate? Just trying to get an overview of all the possibilities here.

Edited for realizing I should look up what it is for before asking silly questions.

Edited by Lucidaxe
Link to comment
Share on other sites

10 minutes ago, Lucidaxe said:

On second thought, would it also be possible to edit TUNING.MOISTURE_SANITY_PENALTY_MAX to set a zero sanity drain rate? Just trying to get an overview of all the possibilities here.

Edited for realizing I should look up what it is for before asking silly questions.

Yes, although I would NOT do it. Like ever.

 

In modmain.lua:

TUNING.WILSON_HEALTH = 20

 

0sMX9jM.jpg

 

Edit: Might need to be GLOBAL.TUNING since I use Kzisor's engine.lua.

Edited by DrSmugleaf
Link to comment
Share on other sites

I see the issue is already solved...

but take a look at the files for the mod character "Womp" and see what you can make of some of the code, since he is a rain based character. 

Just thought it might be useful if you want to expand the theme.

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