Jump to content

Help with Gaining Extra Sanity from Food


Recommended Posts

Hello! I'm making my first mod character and everything is going good. I have textures, sounds, perks, everything is working nicely. However, just to finish up my character I wanted to give her some bonus perks that aren't as obvious just to make her feel more unique. I want her to have extra sanity gain from eating sweet foods like honey, taffy, pumpkin cookies, etc. I've been through quite a few topics on the forums and nothing seems to be working for me. There seems to be a lot of ways of doing this and it's kinda confusing and overwhelming...

Link to comment
Share on other sites

Ah! I know how to do this! My character actually has this perk when eating fruits such as berries, etc. 

	local OldEat = inst.components.eater.Eat
		inst.components.eater.Eat = function(self, food)
		if food and food.components.edible and food.prefab == "berries" then
				food.components.edible.sanityvalue = 2
		end	
		return OldEat(self, food)
	end

and then you replace "berries" with your food item and sanityvalue to what you want :D 
keep in mind that (I think) it adds up!

You add this in your character's prefab file, in local master_postinit = function(inst)

Link to comment
Share on other sites

Finally! Wow, posted and answered in the same day! I didn't want to make my own post because I thought it would take like, a week for a helpful answer! It works like a charm, thanks for the help :3 Also, It doesn't add up, I changed the number to 20 for taffy (which gives 15 sanity) and I got 20 instead of 35. Which is fine in my case :3

Link to comment
Share on other sites

2 minutes ago, Scoobie101 said:

Finally! Wow, posted and answered in the same day! I didn't want to make my own post because I thought it would take like, a week for a helpful answer! It works like a charm, thanks for the help :3 Also, It doesn't add up, I changed the number to 20 for taffy (which gives 15 sanity) and I got 20 instead of 35. Which is fine in my case :3

you could do

food.components.edible.sanityvalue = food.components.edible.sanityvalue + 2

so that way you keep the food's current sanity value and add the 2 as well, in case you wanted to know.

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