Jump to content

Recommended Posts

So, I have a working script at the moment based on just a single prefab to gain sanity. I wanted to go make it a little bit more advanced and I remembered that wark had a custom food table, so using wark as a reference I made my own

GLOBAL.FOODTYPE.OTTERFOOD = "OTTERFOOD"local otter_food = {"fish", "fish_cooked", "fishsticks", "fishtacos", }local function AddOtterFood(inst)    inst:AddTag("edible_"..GLOBAL.FOODTYPE.OTTERFOOD)endfor k,v in pairs(otter_food) do    AddPrefabPostInit(v, AddOtterFood)end
Now when I go to call the foodtype to increase my sanity nothing happens.
local OldEat = inst.components.eater.Eatinst.components.eater.Eat = function(self, food)    if self:CanEat(food) and food.components.edible.foodtype == FOODTYPE.OTTERFOOD then        food.components.edible.sanityvalue = food.components.edible.sanityvalue + 8            end    return OldEat(self, food)endend
 

anyhelp anyone?

Edited by ArashiOtter

Try this putting this fonction on your character prefab :
 

local function oneat(inst, food)     if food and food.components.edible and food.components.edible.foodtype == "OTTERFOOD" then        inst.components.sanity:DoDelta(32)    endend

 
Then call it like this :

inst.components.eater:SetOnEatFn(oneat)

Remember, this will ad a sanity bonus when your character eat something in the foodtype. It will give the same amount of sanity for all items you eat as long as it is in the foodtype  "OTTERFOOD". If the item already gave sanity, this bonus will add.

@ArashiOtter, I'd agree with Pyrobolser with their recommendation. If you are wanting to make each food give a different value for your character, then you'd need to have more code. You'd need to determine what the prefab of the food type, then you'd need to increase your sanity accordingly. All relatively easy, but the solution above is the easiest to start out. 

Ok so I put in @Pyrobolser's code into my character, but it still does not increase sanity on eating. So if I eat a fish which should put my sanity up I do not get a sanity increase at all. But if I eat fishtacos I get a sanity boost, I think it's cause that fishtacos have a sanity bonus. I will attach my whole character any help is greatly appreciated.

Thank you

arashi.zip

@ArashiOtter, edited to show you why your if statement is always returning false.

 

if self:CanEat(food) and food.components.edible.foodtype == FOODTYPE.OTTERFOOD then 

 

In this particular if statement you are trying to determine whether the foodtype is OTTERFOOD which will always return false because you haven't set the food type for the items, you've only added a tag.

 

Instead try:

 

if self:CanEat(food) and food:HasTag("edible_"..FOODTYPE.OTTERFOOD) then 

 

This should make it return true if it has that tag.

Edited by Kzisor

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