Jump to content

[HELP] Removing Mushrooms from Vegetable foodtypes


Recommended Posts

I'm currently making my first custom character and am now just adding my special abilities and drawbacks, of which my absolute hate for mushrooms comes into play. I want my character to have a standard OMNI diet except that they can't eat mushrooms. From what I've found in theory I could remake my own version of the vegetables foodtype but without the mushrooms and then declare my character's diet and edible foodtypes in the modmain or the character.lua, but it seems like it would be far easier, if it is possible, to just remove the 6 or so edible mushrooms from the vegetable table for this character in specific.

Does anyone know if/how this could be done?

Link to comment
Share on other sites

You can extend the Eater:CanEat function of the eater component on your character, and return false early if it is a mushroom. Put this code at the bottom of your character's masterpostinit.

local oldCanEat = inst.components.eater.CanEat
function inst.components.eater:CanEat(inst)
	if inst:HasTag("mushroom") then
		return false
	end
	return oldCanEat(inst)
end

 

Link to comment
Share on other sites

Well, not all mushroom items have the "mushroom" tag, so if you want to make your character unable to eat more foods incl. all the mushrooms, you can always make a list of inedible food items and keep them from being eaten using similar code.

Here's a way to do that:

local inedibles = { "monstermeat", "corn" }

local old_CanEat = inst.components.eater.CanEat

inst.components.eater.CanEat = function(self, food_inst)
	for i, v in ipairs(inedibles) do
		if food_inst.prefab == v then
			return false
		end
	end
	return old_CanEat(self, food_inst)
end

 

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