Jump to content

Recommended Posts

Hiya forum, i've got a modding question, & i'm not sure where to look for advice anywhere but here.

Rundown for my survivor: They're a jack of all trades, able to do some stuff just a little bit better, but not by much. To balance out stuff like 10% extra damage, 10% slower hunger drain, 10% damage resist, i want to add unique downsides inspired from other survivors.

So, here's my question:
I'm wondering how I can make my character not eat specific foods, like anything frog-related, meatballs, or koalefant trunks. I'm trying to make this character a picky eater to restrict foods that they would find gross or overrated, plus it's also gonna be one way i nerf this character (another being their max sanity of 100).

How would I go about this? Is it even possible? Any help is appreciated.

On 12/7/2025 at 7:37 AM, f0rest_crypt1d said:

Hiya forum, i've got a modding question, & i'm not sure where to look for advice anywhere but here.

Rundown for my survivor: They're a jack of all trades, able to do some stuff just a little bit better, but not by much. To balance out stuff like 10% extra damage, 10% slower hunger drain, 10% damage resist, i want to add unique downsides inspired from other survivors.

So, here's my question:
I'm wondering how I can make my character not eat specific foods, like anything frog-related, meatballs, or koalefant trunks. I'm trying to make this character a picky eater to restrict foods that they would find gross or overrated, plus it's also gonna be one way i nerf this character (another being their max sanity of 100).

How would I go about this? Is it even possible? Any help is appreciated.

I followed the instructions of this post and it still works
 

Spoiler
local blocked_foods = {
    "butterflywings", "butterflymuffin", "poop", "moonbutterflywings",
    "butterflymuffin_spice_chili", "butterflymuffin_spice_sugar",
    "butterflymuffin_spice_salt", "butterflymuffin_spice_garlic"
}

local function prefers_to_eat_filtered(inst, food)
    if food ~= nil then
        for _, v in ipairs(blocked_foods) do
            if food.prefab == v then
                return false
            end
        end
    end
    return true
end
---master_postinit---
inst.components.eater.PrefersToEat = prefers_to_eat_filtered

local restricted_foods = {}
local old_can_eat = inst.components.eater.CanEat

inst.components.eater.CanEat = function(self, food_inst)
    for _, v in ipairs(restricted_foods) do
        if food_inst.prefab == v then
            return false
        end
    end
    return old_can_eat(self, food_inst)
end

 

 

Heya! Thanks for the pointers!
I forgot to mention, i'm very much an amateur at modding with this game. I don't know where i should put those code snippets.
I tried putting them in the survivor's .lua file, but no matter which lines the code was on or how i write it, my server would fail to start whenever I activate the mod in-game.
Any idea what i'm doing wrong here?

5 hours ago, f0rest_crypt1d said:

Heya! Thanks for the pointers!
I forgot to mention, i'm very much an amateur at modding with this game. I don't know where i should put those code snippets.
I tried putting them in the survivor's .lua file, but no matter which lines the code was on or how i write it, my server would fail to start whenever I activate the mod in-game.
Any idea what i'm doing wrong here?

Disregard this, I made a rookie mistake. I had to do proper indentation for the code to execute properly.

--This code snippet needs to not just be put in master_postinit, but it should also be indented like stat components or your survivor voice.
local restricted_foods = {}
	local old_can_eat = inst.components.eater.CanEat

	inst.components.eater.CanEat = function(self, food_inst)
		for _, v in ipairs(restricted_foods) do
			if food_inst.prefab == v then
				return false
			end
		end
		return old_can_eat(self, food_inst)
	end

Aside from that minor annoyance, I got it to work! Thanks for the help.

  • Health 1

One very simple way is adding this line to your character prefab; This means they'll only be able to eat foods that have this tag.

inst.components.eater:SetPrefersEatingTag("cool_food_tag")

And for making a food valid for your character you do:

local VALID_FOODS =
{
    "meatballs",
    "bonestew",
    "icecream",
}

for k, v in pairs(VALID_FOODS) do
    AddPrefabPostInit(v, function(inst)
        inst:AddTag("cool_food_tag")
    end)
end
  • Big Ups 1

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