Jump to content

How to make favorite food?


Recommended Posts

Hello, I've been trying to make a mod recently, but there's something that doesn't work, so I'm asking here.
1. When making food mods in general, is it possible to make the mod food the mod maker creates so that only certain characters like it? I've been trying to make one and found this out.
Taking Wurt as an example, I found that inst.components.foodaffinity:AddPrefabAffinity ("durian", 1.93) in the "wurt.lua" file to set the favorite food to durian.

Link to comment
Share on other sites

In my understanding, you're asking two different questions. The AddPrefabAffinity function makes it so that the character receives bonus hunger as a multiple of it's caloric value. For most players, this bonus hunger is 15, but Wurt is a bit weird for whatever reason. However, this favorite food function doesn't actually remove any negative stat, just amplifies hunger stat. The second question, point 1, yes, mod makers can make certain foods more palatable to certain characters. For instance, in Webbers file, he has this:

  1. if inst.components.eater ~= nil then
  2. inst.components.eater:SetStrongStomach(true)
  3. inst.components.eater:SetCanEatRawMeat(true)
  4. end
  5.  
  6. inst.components.foodaffinity:AddPrefabAffinity("icecream", TUNING.AFFINITY_15_CALORIES_MED)

Line 2 says that he can eat monster foods without suffering any negative downsides, he can eat raw meat without losing health or sanity, and his food affinity is ice cream, meaning he gains 15 more calories from ice cream specifically. Lines 2 and 3 are functions with booleans that determine if the character should receive the tag "StrongStomach" and "CanEatRawMeat". If true, they will receive said tags. Those tags are defined in the eater.lua file, where it says

  1. function Eater:DoFoodEffects(food)
  2. return not ((self.strongstomach and food:HasTag("monstermeat")) or
  3. (self.eatsrawmeat and food:HasTag("rawmeat")) or
  4. (self.inst.components.foodaffinity and self.inst.components.foodaffinity:HasPrefabAffinity(food)))
  5. end

It should be fairly straighforward from here.

 

Does that answer your question?

  • Like 1
Link to comment
Share on other sites

1 hour ago, M1chael 39 said:

In my understanding, you're asking two different questions. The AddPrefabAffinity function makes it so that the character receives bonus hunger as a multiple of it's caloric value. For most players, this bonus hunger is 15, but Wurt is a bit weird for whatever reason. However, this favorite food function doesn't actually remove any negative stat, just amplifies hunger stat. The second question, point 1, yes, mod makers can make certain foods more palatable to certain characters. For instance, in Webbers file, he has this:

  1. if inst.components.eater ~= nil then
  2. inst.components.eater:SetStrongStomach(true)
  3. inst.components.eater:SetCanEatRawMeat(true)
  4. end
  5.  
  6. inst.components.foodaffinity:AddPrefabAffinity("icecream", TUNING.AFFINITY_15_CALORIES_MED)

Line 2 says that he can eat monster foods without suffering any negative downsides, he can eat raw meat without losing health or sanity, and his food affinity is ice cream, meaning he gains 15 more calories from ice cream specifically. Lines 2 and 3 are functions with booleans that determine if the character should receive the tag "StrongStomach" and "CanEatRawMeat". If true, they will receive said tags. Those tags are defined in the eater.lua file, where it says

  1. function Eater:DoFoodEffects(food)
  2. return not ((self.strongstomach and food:HasTag("monstermeat")) or
  3. (self.eatsrawmeat and food:HasTag("rawmeat")) or
  4. (self.inst.components.foodaffinity and self.inst.components.foodaffinity:HasPrefabAffinity(food)))
  5. end

It should be fairly straighforward from here.

 

Does that answer your question?

Hmm... the description of the lua edit for the character was absolutely perfect. But the mod I'm going to make is a mod that adds food. This food requires the Wurt to receive a recovery bonus and all other characters except Wurt have a -recovery value.

Edited by boom_night
Link to comment
Share on other sites

5 hours ago, boom_night said:

Hmm... the description of the lua edit for the character was absolutely perfect. But the mod I'm going to make is a mod that adds food. This food requires the Wurt to receive a recovery bonus and all other characters except Wurt have a -recovery value.

What's recovery? And whatever it is, I was trying to illustrate that it's definitely possible to do so, as Klei has done it earlier. When the server runs with mods, it doesn't really distinguish what is and isnt a mod food, except for like, looking at it in the cookbook.

Link to comment
Share on other sites

8 hours ago, M1chael 39 said:

What's recovery? And whatever it is, I was trying to illustrate that it's definitely possible to do so, as Klei has done it earlier. When the server runs with mods, it doesn't really distinguish what is and isnt a mod food, except for like, looking at it in the cookbook.

That means, there is no way to remove the debuff that is given when only a certain character eats food by defining a character only in the food mode?

Are you saying that this is a syntax that can only be applied to character files?

Link to comment
Share on other sites

On 10/19/2021 at 5:03 AM, boom_night said:

That means, there is no way to remove the debuff that is given when only a certain character eats food by defining a character only in the food mode?

Are you saying that this is a syntax that can only be applied to character files?

Hello, sorry for the late reply.

I will try to address what you are asking, although I am kinda unsure of what you are asking.

I can make all characters lose 20 sanity and health from a new food, applejacks, whilst gaining 30 hunger. I can add in a tag called "applejacks-lover" to my new character, Wepeatski, which will make him ignore all the downsides that the food applejacks will give him. You could also create a conditional statement on the food (a food "buff") inside the food's prefab file which makes it such that, if the eater shares the same prefab with specific characters (say, wepeatski and webber), then the consumed health and sanity are 0 instead of -20, while still giving the default hunger value.

 

Does that answer your question?

Link to comment
Share on other sites

On 10/23/2021 at 3:34 AM, M1chael 39 said:

Hello, sorry for the late reply.

I will try to address what you are asking, although I am kinda unsure of what you are asking.

I can make all characters lose 20 sanity and health from a new food, applejacks, whilst gaining 30 hunger. I can add in a tag called "applejacks-lover" to my new character, Wepeatski, which will make him ignore all the downsides that the food applejacks will give him. You could also create a conditional statement on the food (a food "buff") inside the food's prefab file which makes it such that, if the eater shares the same prefab with specific characters (say, wepeatski and webber), then the consumed health and sanity are 0 instead of -20, while still giving the default hunger value.

 

Does that answer your question?

I understand to some extent what you are saying.
But you are explaining inside the food's prefab needed to make character mods. (foodbuffs.lua) I'm making food mods, not character mods. Everything in foodbuffs.lua is what you need to make character mods. Therefore, it was not helpful for me. To help you understand, I'll show you a part of 'modmain.lua' in the food mod I'm making below.

Quote

local durianpie =
{
    name = "durianpie",
    test = function(cooker, names, tags) return (names.durian or names.durian_cooked) and tags.inedible and tags.veggie and not tags.meat end,
    priority = 15,
    weight = 1,
    foodtype = "MONSTER",
    health = -TUNING.HEALING_HUGE,
    hunger = -TUNING.CALORIES_HUGE,
    sanity = -TUNING.SANITY_SMALL,
    perishtime = TUNING.PERISH_SLOW,
    cooktime = 1,
    --I want wurt to recover by eating durianpie (I want all other characters except wurt to consume hunger, sanity and health when eating this food).
}
AddCookerRecipe("cookpot",durianpie)

 

Link to comment
Share on other sites

Ok, I see what you are saying. Ok, how you are trying to do it is going to be a bit tougher, but I think ik how to do it. How you want to construct it is like this: in the crockpot recipe, which you have given below, you don't include the function that modifies how many calories Wurt receives. Instead, you would do that in the prefab file for durianpie. I will be using the code for "Zaspberry Parfait" from uncomp as the basis, then constructing the Wurt recovering bit. What it should look like is this:

  1. local assets =
  2. {
  3. Asset("ANIM", "anim/zaspberryparfait.zip"),
  4. Asset("ATLAS", "images/inventoryimages/zaspberryparfait.xml"),
  5. --Asset("IMAGE", "images/inventoryimages/zaspberryparfait.tex"),
  6. }
  7.  
  8. local function oneatenfn(inst, eater)
    1. if prefab.eater == Wurt
      1. eater.inst.components.hunger:DoDelta(-1 * food.components.edible:GetHunger(self.inst))
      2. and do the same for the sanity and health
      3. end
  9. end
... some more code we dont care about
  1. return Prefab("zaspberryparfait", fn, assets)
 
Try doing something like that.
Link to comment
Share on other sites

Quote

 

On 10/25/2021 at 7:33 AM, M1chael 39 said:

Ok, I see what you are saying. Ok, how you are trying to do it is going to be a bit tougher, but I think ik how to do it. How you want to construct it is like this: in the crockpot recipe, which you have given below, you don't include the function that modifies how many calories Wurt receives. Instead, you would do that in the prefab file for durianpie. I will be using the code for "Zaspberry Parfait" from uncomp as the basis, then constructing the Wurt recovering bit. What it should look like is this:

  1. local assets =
  2. {
  3. Asset("ANIM", "anim/zaspberryparfait.zip"),
  4. Asset("ATLAS", "images/inventoryimages/zaspberryparfait.xml"),
  5. --Asset("IMAGE", "images/inventoryimages/zaspberryparfait.tex"),
  6. }
  7.  
  8. local function oneatenfn(inst, eater)
    1. if prefab.eater == Wurt
      1. eater.inst.components.hunger:DoDelta(-1 * food.components.edible:GetHunger(self.inst))
      2. and do the same for the sanity and health
      3. end
  9. end
... some more code we dont care about
  1. return Prefab("zaspberryparfait", fn, assets)
 
Try doing something like that.

Sorry for the late reply. As you said in the ltemname.lua file in the prefabs folder:

local function oneatenfn(inst, eater)
		if prefab.eater == Wurt
		eater.inst.components.hunger:DoDelta(-1 * food.components.edible:GetHunger(self.inst))
		and do the same for the sanity and health
	end
end

to run the mod, but I found that the execution did not work normally. therefore:

local function oneatenfn(inst, eater)
		if prefab.eater == wurt then
		eater.inst.components.sanity:DoDelta(-1 * food.components.edible:GetSanity(self.inst))
	end
end

I modified it like this and tried to run the server. However, while running is normal, nothing has changed.
I roughly understood the content of the syntax you gave me. I also understood the principle of making a negative number positive by multiplying -1 by the value of the mod food in:

DoDelta(-1 * food.components.edible:GetSanity(self.inst))

please help again
And thank you so much for your continued help.

Edited by boom_night
Link to comment
Share on other sites

No problem, any time. Although I could probably write the code correctly, I think the modders at Hornets Hive would probably be more able to help you right now, as they're much more experienced than I. This is their discord link: https://discord.gg/vVbFEhr
I can probably help you more later, but I would want to find a better solution to your problem, and to be frank, they're simply more experienced than me.

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