Jump to content

Recommended Posts

Hiya!

So I'm super new to mod making, so bear with me here. I understand the basics, but this one little aspect I'd like to add to my character has me wanting to bash my face into a wall.

To put it simply, my character that I'm making is whack. She is an escaped sanitorium patient. So to reflect that, I'd like to slightly cap her sanity, just enough so that by default, she'll always be seeing the shadow creatures. 

I've been trying to achieve this by looking at the code for various revival items, like the Tell-Tale Heart. booster shots, etc, since those aspects involve capping the health bar with a small penalty. I've tried adding SetPenalty, DoDelta, basically everything else that could even possibly exist- But everything I've tried has led to either a solid crash, or just doing nothing. I assume that this penalty should be set under inst.components, but I could easily be wrong about that. I've tried poking around other people's mods to see if anyone else has done something similar, but weirdly I haven't stumbled across *anything*. It's driving me crazy!

So yeah! If anyone else has ideas that might work, I'd really appreciate them. Until then, I figure I can settle with just a small constant sanity drain, but that's not really ideal for gameplay of course. 

Thank you! 

Link to comment
https://forums.kleientertainment.com/forums/topic/136912-mod-help-sanity-penalty/
Share on other sites

7 hours ago, nauseatinghusk said:

IF it's impossible to cap sanity at the start of the game without the cap being caused by something, is it possible to have the passive shadow creatures be displayed without the player having the craziness status, perhaps?

Doing it like that would be a lot harder, though cleaner to do, I recommend you stick to the normal penalty system, set it on spawn and respawn and there shouldn't be a way to undo it.

I would add the penalty using AddSanityPenalty, I'm not sure why it didn't work for you but we can try again together, as it IS the proper way to do it if you want something similar to Maxwell's sanity penalty. The awesome thing is, it's really easy to do! You just gotta make sure you do it in the right places, which I'll guide you through doing.

Here's the magic line of code, with too many comments
 

	-- PermaPenalty is essentially just a keyword to make sure the penalty isn't added twice 
	-- If another "PermaPenalty" sanity penalty tries to add itself, it will fail since one already exists.
	-- The number, in this case 0.5, is just the multiplier for your max sanity. Simple enough.

	inst.components.sanity:AddSanityPenalty("PermaPenalty", 0.5) 

We'll want to put this in your character prefab.lua, namely under the 2 functions onbecamehuman, and onload. I'm gonna use a snippet from the esctemplate in an example here, if we wanted to add it to onbecamehuman, the function would look like this.

-- When the character is revived from human
local function onbecamehuman(inst)
	-- Add 50% permanent sanity penalty
	inst.components.sanity:AddSanityPenalty("PermaPenalty", 0.5)
	
	-- Set speed when not a ghost (optional)
	inst.components.locomotor:SetExternalSpeedMultiplier(inst, "esctemplate_speed_mod", 1)
end

Simple enough, just add the line anywhere in the functions I listed above. If you do both, it should ensure your character always has the penalty.

Edit: I assume you used esctemplate for your character, if you didn't I can help add the right functions to get this working.

Edited by TheSkylarr
  • Like 1
13 hours ago, TheSkylarr said:

Doing it like that would be a lot harder, though cleaner to do, I recommend you stick to the normal penalty system, set it on spawn and respawn and there shouldn't be a way to undo it.

I would add the penalty using AddSanityPenalty, I'm not sure why it didn't work for you but we can try again together, as it IS the proper way to do it if you want something similar to Maxwell's sanity penalty. The awesome thing is, it's really easy to do! You just gotta make sure you do it in the right places, which I'll guide you through doing.

Here's the magic line of code, with too many comments
 


	-- PermaPenalty is essentially just a keyword to make sure the penalty isn't added twice 
	-- If another "PermaPenalty" sanity penalty tries to add itself, it will fail since one already exists.
	-- The number, in this case 0.5, is just the multiplier for your max sanity. Simple enough.

	inst.components.sanity:AddSanityPenalty("PermaPenalty", 0.5) 

We'll want to put this in your character prefab.lua, namely under the 2 functions onbecamehuman, and onload. I'm gonna use a snippet from the esctemplate in an example here, if we wanted to add it to onbecamehuman, the function would look like this.


-- When the character is revived from human
local function onbecamehuman(inst)
	-- Add 50% permanent sanity penalty
	inst.components.sanity:AddSanityPenalty("PermaPenalty", 0.5)
	
	-- Set speed when not a ghost (optional)
	inst.components.locomotor:SetExternalSpeedMultiplier(inst, "esctemplate_speed_mod", 1)
end

Simple enough, just add the line anywhere in the functions I listed above. If you do both, it should ensure your character always has the penalty.

Edit: I assume you used esctemplate for your character, if you didn't I can help add the right functions to get this working.

You are a GEM! AN ABSOLUTE GEM! That's exactly what I needed and it works PERFECTLY! THANK YOU SO MUCH. This danged thing has been a thorn in my side for MONTHS. You saved me! I hope nothing but good happens to you for the entirety of 2022. <3

2 hours ago, nauseatinghusk said:

You are a GEM! AN ABSOLUTE GEM! That's exactly what I needed and it works PERFECTLY! THANK YOU SO MUCH. This danged thing has been a thorn in my side for MONTHS. You saved me! I hope nothing but good happens to you for the entirety of 2022. <3

Haha, glad you got it working! If you need any more help make sure to make a new thread, or there's also a discord channel in the Don't Starve Discord server where people can help you.

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