Jump to content

Help with a character that loses sanity instead of health when hungry


Recommended Posts

Hi, everyone, I've been making my first Don't Starve Together character mod. One of the "perks" she has is that when she's starving, she does not lose any health. Instead she loses sanity at double the rate that other characters lose health. I've messed around with a few things, but I couldn't get anything that works the way I want it to. Can anyone help me, or at least give me an idea of how I start working on this? Any help you can give would be much appreciated!

 

I might be able to get the sanity part working on my own with enough work, but I am completely lost when it comes to removing the hunger damage.

 

(reposting this because I accidently put it in tutorials and guides. I am a forum dumbo)

Link to comment
Share on other sites

First of all, it works! When my character is at 0 hunger, she doesn't take damage! However, I still have a few issues.

1. Whenever I recover hunger and stop starving, my character still keeps losing sanity until I leave the game.

2. The health icon has a large down arrow on it which would make the player think they are losing health. I want to get rid of that arrow. I remember I found a way to change the arrow on the sanity icon, but I could not get it to work for health.

3. Is there any way to replace the red screen effect when a character starves? It's fine if there isn't, but I just feel like it sends the wrong message to players.

This is what I added into master_postinit

--Weave loses sanity instead of health when starving
inst.components.hunger:SetOverrideStarveFn(function(inst)
  -- insert sanity loss here
	inst.components.sanity.dapperness = -2.5
end)

 

Link to comment
Share on other sites

On 11/19/2020 at 11:36 PM, SSM Steve said:

2. The health icon has a large down arrow on it which would make the player think they are losing health. I want to get rid of that arrow. I remember I found a way to change the arrow on the sanity icon, but I could not get it to work for health.

3. Is there any way to replace the red screen effect when a character starves? It's fine if there isn't, but I just feel like it sends the wrong message to players.

The black down arrow is handled in widgets\healthbadge.lua in the OnUpdate function, and the red onscreen effect is handled in widgets\bloodover.lua in the UpdateState function. Unfortunately, as you can see these are hardcoded to trigger when starving (replica.hunger:IsStarving() returns true when hunger <= 0). Unlike with something like fire for example, where the client has access to networked variables that describe how much damage the player is taking, there is no way for the client to actually determine if they are taking starvation damage or not (which, to be honest, seems kind of strange given that SetOverrideStarveFn is a thing, though I guess maybe it was never meant to be used for players).

Anyway, you have a couple of options at this point. You could override the above functions with your desired functionality (note that they are widgets, so they should only be modified with client-side code), or you could modify replica.hunger:IsStarving() to always return false for your character. The latter method seems less messy in my opinion, so I went with that.

AddClassPostConstruct("components/hunger_replica", function(self)
        local _IsStarving = self.IsStarving
        function self:IsStarving()
                if self.inst:HasTag("nostarvedamage") then
                	return false
                else
               		return _IsStarving(self)
                end
        end
end)

 As you can see above, I used a tag "nostarvedamage" to make this reusable for other characters or situations, so you'll need to add that tag to your character. If you don't care about reusability though, then you can replace that tag check with self.inst.prefab == "your character name here".

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