Jump to content

Recommended Posts

I somehow magically found out what you were trying to accomplish via my telepathic capabilities and so I bring you this:

AddPrefabPostInit("put_the_name_of_your_furry_character_mod's_prefab_name_here",function(inst)
	if inst.components.eater~=nil then
		local _TestFood_Old = inst.components.eater.TestFood or (function() return end)
		inst.components.eater.TestFood = function(self,food,testvalues)
			if food:HasTag("honeyed") then
				return true
			end
			return false
			--return _TestFood_Old(self,food,testvalues)
		end
	end
end)

 

FOODTYPE is a global table defined in constants.lua

FOODTYPE =
{
    GENERIC = "GENERIC",
    MEAT = "MEAT",
    WOOD = "WOOD",
    VEGGIE = "VEGGIE",
    ELEMENTAL = "ELEMENTAL",
    GEARS = "GEARS",
    HORRIBLE = "HORRIBLE",
    INSECT = "INSECT",
    SEEDS = "SEEDS",
    BERRY = "BERRY", --hack for smallbird; berries are actually part of veggie
    RAW = "RAW", -- things which some animals can eat off the ground, but players need to cook
    BURNT = "BURNT", --For lavae.
    ROUGHAGE = "ROUGHAGE",
    GOODIES = "GOODIES",
}

 

to add a custom food type, simply

GLOBAL.FOODTYPE.MYFOODTYPE="MYFOODTYPE"

I know this is an older post, but I found myself struggling when trying to get Butterflies (when held in inventory) to eat a specific item, but disallow all other creature from eating said item. I used a combination of what was said in this post and in another post to do it and figured I'd post my solution here in case someone finds this thread like I did:

Firstly, we since I didn't want anything or anyone else being able to eat the food, I needed to add it a new FoodType at the global level:
 

GLOBAL.FOODTYPE.DEATH = "DEATH"


This would allow the item I was modifying to have it's own food type. Then, I made the item edible and gave it the food type.
 

AddPrefabPostInit("ghostflower", function(inst)
    if not GLOBAL.TheWorld.ismastersim then
        return
    end

    inst:AddComponent("edible")
    inst.components.edible.foodtype = GLOBAL.FOODTYPE.DEATH
    inst.components.edible.healthvalue = 0
    inst.components.edible.hungervalue = 0
    inst:AddTag("edible_" .. GLOBAL.FOODTYPE.DEATH)
end)

You'll notice that I added a Tag to the food as well, which, translated from the above LUA syntax, is 'edible_DEATH'. This is because the creature I want to add it to is the Butterfly, which needs to be fed by the player, but the logic that determines if you can even ATTEMPT to feed the butterfly checks for this specific tag.

Lastly, I needed to make the Butterflies capable of eating my new food group:
 

AddPrefabPostInit("butterfly", function(inst)
    if not GLOBAL.TheWorld.ismastersim then
        return
    end

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

	local _TestFood_Old = inst.components.eater.TestFood or (function() return false end)
	inst.components.eater.TestFood = function(self ,food, testvalues)
		if _TestFood_Old == false then
			if food:HasTag("edible_" .. GLOBAL.FOODTYPE.DEATH) then
				return true
			end
			return false
		end
		return true
	end

	table.insert(inst.components.eater.caneat, GLOBAL.FOODTYPE.DEATH)
	inst:AddTag(GLOBAL.FOODTYPE.DEATH .. "_eater")
end)

A couple things are happening here. First, I make sure that the Butterflies are 'eaters' (they are by default, but that's a sanity check). Then, I am updating the Butterfly's 'TestFood' function. The 'TestFood' function determines if the eater CAN eat the food. It's used by eaters like Wigfrid who can ATTEMPT to eat anything, but fail to eat non-meats. What I am doing is saying "run the original TestFood, and if it fails, check to see if the food is of the 'edible_DEATH' type." Thanks @JohnWatson above for that helpful bit of code!

Lastly, we need to update the Butterfly's eater code to allow it to eat the DEATH food and we need to do this in two different ways. First, we need to add the food group to the Butterfly's DIET or 'caneat'. I originally used the 'SetDiet()' function, but that failed in multiple ways because it replaces the original diet of the creature. Instead, we use "table.insert", to add the new food type to the Butterfly's list of accepted foods. Second, we do the same thing we did before with the Mourning Glories (ghostflower) - we tag the Butterfly with 'DEATH_eater' so that the code can recognize that we want to be able to feed the Butterfly DEATH foods.

Hope this helps anyone else trying to do niche coding with FoodTypes!

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