Jump to content

Like/Disliked foods - Gaining more or less sanity from certain foods


Recommended Posts

I want to program characters to have foods they like and dislike, giving or draining sanity even when it normally doesn't. How does one go about doing that? Not as groups, but individual foods.

And while we're on the subject, how does one make a character reject a food? Like when trying to get Wigfrid to eat non-meats or any character to eat the fruitcake?

Link to comment
Share on other sites

I'm not sure about the first question but for the second question it's eater:SetDiet(caneat, preferseating).  Both of the arguments are tables and what ever is in the caneat but not the preferseating will be rejected.

Link to comment
Share on other sites

20 minutes ago, Wolf_EX said:

I'm not sure about the first question but for the second question it's eater:SetDiet(caneat, preferseating).  Both of the arguments are tables and what ever is in the caneat but not the preferseating will be rejected.

Let's say that a food normally restores 5 sanity. If I want the character to like it, it will restore a set amount more, like 10 more, giving 15 sanity. If I want the character to dislike it, I'll do the same but with negative numbers, like -10, draining 5 sanity.

Took me a while to get what you were sayin' with the tables, but I dunno how to set up tables. Or at least I might, but don't know that they're called tables.

Link to comment
Share on other sites

--example methods, you can basically use this to deem any food to the precision you desire.
local favorites = {
	waffles = true,
	frogglebunwich = true,
	bonestew = true,
	perogies = true,
	meatballs = true,
}
local function oneat(inst, food)
	if food and food.components.edible then
		if favorites[food.prefab] then --love
			inst.components.sanity:DoDelta(TUNING.SANITY_TINY)
		elseif food:HasTag("preparedfood") then --crockpot
			inst.components.sanity:DoDelta(TUNING.SANITY_TINY*0.6)
		elseif food.components.cookable then --raw
			inst.components.sanity:DoDelta(-TUNING.SANITY_TINY*0.6)
		end
	end
end

All code below this is in the master_postinit

master_postinit

    inst.components.eater:SetOnEatFn(oneat)

If you want to flat out reject specific foods. Here is a example from one of my my characters who refuses to eat meat with sanity penalties.

	local _PrefersToEat = inst.components.eater.PrefersToEat --this incidentally hits monster meat in all its forms. Kind of like a reverse strong stomach?
	inst.components.eater.PrefersToEat = function(self, food) --do we really need to check for components? food is edible always or we can't eat it?
		return _PrefersToEat(self, food) and not ((food.components.edible.ismeat or food.components.edible.foodtype == FOODTYPE.MEAT) and food.components.edible.sanityvalue < 0)
	end

The basic concept is we backup PrefersToEat function and return the original as long as our conditions are met. You can use the method we used above as well to compare to favorite foods or tags etc.

Edited by IronHunter
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...