Jump to content

Making a character eat an item from outside their diet


Recommended Posts

I have a custom character with a very strict diet, being locked to eating only her foodgroup which consists of nightmare fuel. I would like to make her able to eat grim galettes and carrots too, but they both belong to the veggie foodtype which she can't eat, and as far as i can tell an item can only belong to one foodtype. Is there a way to make her eat these 2 items as well?

Link to comment
Share on other sites

Since your character's diet seems to be very strict and specific, you could handle it with tags instead, like Warly. Basically, add a tag to every food you want her to be able to eat. Something like this somewhere in modmain:

local CAN_ONLY_EAT = {
	"nightmarefuel",
	"carrot",
	"carrot_cooked",
	"nightmarepie",
}

for k,v in pairs(CAN_ONLY_EAT) do
	AddPrefabPostInit(v, function(inst)
		inst:AddTag("yourtagnamehere") -- Change this
	end)
end

And something like this in your character prefab file, in the master postinit function:

if inst.components.eater ~= nil then
	inst.components.eater:SetPrefersEatingTag("yourtagnamehere") -- Change this
end

Remember to change the tag name to whatever you like!

Though you're going to need to do some extra steps for the items that aren't normally edible, like Nightmare Fuel, otherwise the prompt to eat them won't show up. You'll need to add the edible component and assign the food type and the health/hunger/sanity values, which I assume you've already done, if not and you need help, feel free to ask!

  • Thanks 1
  • Wavey 1
Link to comment
Share on other sites

Thank you for the help, it works for the most part, but i can't seem to get her to eat nightmare fuel. I've assigned it stats and a foodtype but the prompt to eat it still doesn't show.

I have this in my modmain

GLOBAL.FOODTYPE.WILDCARD_EDIBLE = "WILDCARD_EDIBLE"

--[[
GLOBAL.FOODGROUP.WILDCARDDIET = {
    name = "WILDCARDDIET",
    types = {
		GLOBAL.FOODTYPE.WILDCARD_EDIBLE
    }
}
--]]

local CAN_ONLY_EAT = {
	"carrot",
	"carrot_cooked",
	"nightmarepie",
}

for k,v in pairs(CAN_ONLY_EAT) do
	AddPrefabPostInit(v, function(inst)
		inst:AddTag("horrorbunnygirl")
	end)
end

AddPrefabPostInit("nightmarefuel", function(inst)

	inst:AddTag("horrorbunnygirl")

    if not GLOBAL.TheWorld.ismastersim then
        return inst
    end

    if inst.components.edible == nil then
        inst:AddComponent("edible")        
    end

    local e = inst.components.edible
    e.foodtype = "WILDCARD_EDIBLE"
    e.healthvalue = 25
    e.hungervalue = 20
    e.sanityvalue = -5
    
end)

and this in my character.lua

	if inst.components.eater ~= nil then
	inst.components.eater:SetPrefersEatingTag("horrorbunnygirl")
	--inst.components.eater:SetDiet({ FOODGROUP.OMNI, FOODGROUP.WILDCARDDIET }, { FOODTYPE.WILDCARD_EDIBLE })
	
    end

am i missing something?

Link to comment
Share on other sites

4 hours ago, Mentos said:

am i missing something?

Yes, she still needs to have your new foodtype as part of her diet, otherwise the prompt won't show up. Just like how Rocks are technically food, but players are never given the prompt to try to eat them.

The first argument in "SetDiet" is the table of food types your character can **try** to eat, the second is the table of what they will actually eat. For example, Wigfrid can attempt to eat anything a regular character can, but will refuse anything but Meat and Goodies. Your custom tag will further filter out what she can eat, so don't worry about it messing up her intended diet.

Something like this should work:

inst.components.eater:SetDiet({ FOODGROUP.OMNI, FOODTYPE.WILDCARD_EDIBLE }, { FOODGROUP.OMNI, FOODTYPE.WILDCARD_EDIBLE })

 

  • Thanks 1
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...