Jump to content

Swapped Sanity (Increase Night, Lower Day)


Recommended Posts

Hey everyone! New to the DST modding community.

I'm trying to create a mod based off of me and my friends characters from another game, however the problem that I'm currently having is that I want to swap the Sanity gain during daytime/night time.

As of right now I think I have things working semi-correctly but I'm not 100% sure on the matter.

This is currently what it looks like.
 

  inst.components.sanity.custom_rate_fn=
  function(inst)
    local dapperness = 0
    local lightval = inst.LightWatcher:GetLightValue()

    local day = TheWorld.state.isday and not TheWorld:HasTag("cave")

    if day then
      dapperness = TUNING.SANITY_NIGHT_DARK * 0.2
    else
      local lowval = TUNING.SANITY_LOW_LIGHT

      if lightval <= lowval then
        dapperness = TUNING.SANITY_NIGHT_DARK
        dapperness = -1 * dapperness
      else
        dapperness = 0;
      end
    end

    return dapperness

  end


It feels a bit off however. Throughout the day, Sanity drops to about 150-160 (From 200) and during the night it ends up back at around 170? I feel like in the winter nights this might be a bit too much.

I was also hoping to make it so that during "Dusk" time no Sanity gain or decrees would happen, however that doesn't appear to work.

Any help would be highly appreciated!

-----

One other side note, I'm trying to also add an aura to another Character that gives +1 science to everyone around you in a radius (Similar to that of the Science machine) however I had no luck there either.

 

Edited by Toonic
Link to comment
Share on other sites

5 hours ago, Toonic said:

It feels a bit off however. Throughout the day, Sanity drops to about 150-160 (From 200) and during the night it ends up back at around 170? I feel like in the winter nights this might be a bit too much.

I was also hoping to make it so that during "Dusk" time no Sanity gain or decrees would happen, however that doesn't appear to work.

Any help would be highly appreciated!

Well, a problem I see is that you get two different sanity debuffs in the night.

The one where you are near lights, and the one where you are in total darkness.

So if you inverse it, you can get a huge sanity buff in the dark during the night.

I suggest:

inst.components.sanity.custom_rate_fn = function(inst)
	local light_delta = 0
	if TheWorld.state.isday then
		light_delta = TUNING.SANITY_NIGHT_MID
	elseif TheWorld.state.isnight then
		light_delta = TUNING.DAPPERNESS_MED
	end
	return light_delta
end

inst.components.sanity.night_drain_mult = 0

The night_drain_mult makes it so regardless of light level, night doesn't affect you.

So you can tune the values like you want in custom_rate_fn.

In this function, if it's day, then the value is like during the night, near lights.

If it's dusk, nothing enters ifs, so returns 0.

If it's night, the value is like wearing a top hat.

5 hours ago, Toonic said:

One other side note, I'm trying to also add an aura to another Character that gives +1 science to everyone around you in a radius (Similar to that of the Science machine) however I had no luck there either.

In common_postinit:

inst:AddTag("selfprototyper")

give your character a special tag.

In master_postinit:

inst:AddComponent("prototyper")
inst.components.prototyper.trees = TUNING.PROTOTYPER_TREES.SCIENCEMACHINE
table.insert(inst.components.builder.exclude_tags, "selfprototyper")

make your character a prototyper with the science machine tech trees. Also add that tag to the tags to exclude, or you will be a science machine to yourself and won't be able to use anything else, like an alchemy engine.

If you want a science bonus, like Wickerbottom, then also in master_postinit:

inst.components.builder.science_bonus = 1

 

Link to comment
Share on other sites

21 minutes ago, DarkXero said:

Well, a problem I see is that you get two different sanity debuffs in the night.

The one where you are near lights, and the one where you are in total darkness.

So if you inverse it, you can get a huge sanity buff in the dark during the night.

I suggest:


inst.components.sanity.custom_rate_fn = function(inst)
	local light_delta = 0
	if TheWorld.state.isday then
		light_delta = TUNING.SANITY_NIGHT_MID
	elseif TheWorld.state.isnight then
		light_delta = TUNING.DAPPERNESS_MED
	end
	return light_delta
end

inst.components.sanity.night_drain_mult = 0

The night_drain_mult makes it so regardless of light level, night doesn't affect you.

So you can tune the values like you want in custom_rate_fn.

In this function, if it's day, then the value is like during the night, near lights.

If it's dusk, nothing enters ifs, so returns 0.

If it's night, the value is like wearing a top hat.

In common_postinit:


inst:AddTag("selfprototyper")

give your character a special tag.

In master_postinit:


inst:AddComponent("prototyper")
inst.components.prototyper.trees = TUNING.PROTOTYPER_TREES.SCIENCEMACHINE
table.insert(inst.components.builder.exclude_tags, "selfprototyper")

make your character a prototyper with the science machine tech trees. Also add that tag to the tags to exclude, or you will be a science machine to yourself and won't be able to use anything else, like an alchemy engine.

If you want a science bonus, like Wickerbottom, then also in master_postinit:


inst.components.builder.science_bonus = 1

 



Thanks for all of that! I'll definitely look into it a bit more. I knew what I was aiming for but just wasn't 100% sure on how to go about doing it. The way you proposed it makes it seem a lot better than the way I was doing it so thanks for that.

However as for the the aura to make a character act as a science machine (Including for other players) I don't see how that works. Unless Prototyper.trees has something to do with that.

As for the builder.science_bonus = 1, I knew about that and had that currently setup for the character.

Link to comment
Share on other sites

5 minutes ago, Toonic said:

However as for the the aura to make a character act as a science machine (Including for other players) I don't see how that works. Unless Prototyper.trees has something to do with that.

All players have the builder component.

Each game tick, that component updates, calling a function inside it called EvaluateTechTrees.

That function looks for entities with the prototyper tag, within a tile distance (4 units) of the player.

Then it looks for the tech trees the entity with prototyper gives.

 

When adding the prototyper component to an entity, among other things, the tag is given.

After that, you specify the tech tree. In this case, we use the same tech tree as the science machine.

 

exclude_tags is a table to specify tags that make a prototyper unusable for your character.

For example, "INLIMBO". This way, Maxwell can't use his book to use as prototyper for shadows, when it's in his inventory.

I gave your character a personal tag, so he doesn't see find himself as the nearest prototyper, meaning he would never use an alchemy engine.

Link to comment
Share on other sites

9 hours ago, DarkXero said:

All players have the builder component.

Each game tick, that component updates, calling a function inside it called EvaluateTechTrees.

That function looks for entities with the prototyper tag, within a tile distance (4 units) of the player.

Then it looks for the tech trees the entity with prototyper gives.

 

When adding the prototyper component to an entity, among other things, the tag is given.

After that, you specify the tech tree. In this case, we use the same tech tree as the science machine.

 

exclude_tags is a table to specify tags that make a prototyper unusable for your character.

For example, "INLIMBO". This way, Maxwell can't use his book to use as prototyper for shadows, when it's in his inventory.

I gave your character a personal tag, so he doesn't see find himself as the nearest prototyper, meaning he would never use an alchemy engine.

Ah, that makes since. I'm only just getting started with modding in Don't Starve, so I'm still trying to wrap my head around everything.

Thanks for that!

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