Jump to content

Recommended Posts

Hi,

 

I want my char to be able to eat petals (yes I know it's already edible) but not any other veggies.

 

So I set

GLOBAL.FOODTYPE.MYCHARSFOOD = "MYCHARSFOOD"
local mychar_food = {"twigs", "log", "boards", "petal", "petal_evil", "pinecone", "cutgrass", "foliage", "cutlichen"}
local function AddMyCharFood(inst)
    inst:AddTag("edible_"..GLOBAL.FOODTYPE.MYCHARSFOOD)
end
for k,v in pairs(mychar_food) do
    AddPrefabPostInit(v, AddMyCharFood)
end
(inside modmain.lua)
 
and

 

inst.components.eater.foodprefs = { FOODTYPE.MYCHARSFOOD }

 

local oldEater = inst.components.eater.Eat

inst.components.eater.Eat = function(self, food)

  if self:CanEat(food) then

    if food.prefab == "twigs" then

      food.components.edible.healthvalue = 2

      food.components.edible.hungervalue = 0

      food.components.edible.sanityvalue = 0

   elseif food.prefab == "petals" then

      food.components.edible.healthvalue = 2

      food.components.edible.hungervalue = 2

      food.components.edible.sanityvalue = 1

--other elseif here

    end

  end

  return oldEater(self, food)

end

(inside mychar.lua, inside master_postinit)

 

So my char is able to eat twigs but not petals because petals foodtype is still VEGGIES.

I don't want to change petals foodtype though.

I don't want mychar to be able to eat any other VEGGIES either.

 

I read below

http://forums.kleientertainment.com/topic/48308-how-do-i-make-my-character-able-to-eat-grass/?hl=edible#entry596414

but that's slightly different scenario/case.

 

Any help or hint?

 

Thanks.

inst.components.edible.foodtype = "MYCHARFOOD" --for petals

and

​inst.components.eater.foodprefs = { "MYCHARFOOD" } --for character  

 

Also look at "edible" and "eater" components. It is in edible.lua and eater.lua files.

 

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