ArashiOtter Posted January 17, 2015 Share Posted January 17, 2015 (edited) 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 ownGLOBAL.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)endNow 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 January 17, 2015 by ArashiOtter Link to comment https://forums.kleientertainment.com/forums/topic/49272-sanity-gain-on-eating-a-certain-food-type/ Share on other sites More sharing options...
Kzisor Posted January 17, 2015 Share Posted January 17, 2015 @ArashiOtter, could you upload the files so we may look at them. This will help us help find you an answer. Link to comment https://forums.kleientertainment.com/forums/topic/49272-sanity-gain-on-eating-a-certain-food-type/#findComment-602882 Share on other sites More sharing options...
Pyrobolser Posted January 17, 2015 Share Posted January 17, 2015 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. Link to comment https://forums.kleientertainment.com/forums/topic/49272-sanity-gain-on-eating-a-certain-food-type/#findComment-603005 Share on other sites More sharing options...
ArashiOtter Posted January 17, 2015 Author Share Posted January 17, 2015 Here are my modmain and character prefab files.modmain.luaarashi.lua Link to comment https://forums.kleientertainment.com/forums/topic/49272-sanity-gain-on-eating-a-certain-food-type/#findComment-603041 Share on other sites More sharing options...
Kzisor Posted January 17, 2015 Share Posted January 17, 2015 @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. Link to comment https://forums.kleientertainment.com/forums/topic/49272-sanity-gain-on-eating-a-certain-food-type/#findComment-603042 Share on other sites More sharing options...
ArashiOtter Posted January 17, 2015 Author Share Posted January 17, 2015 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 youarashi.zip Link to comment https://forums.kleientertainment.com/forums/topic/49272-sanity-gain-on-eating-a-certain-food-type/#findComment-603059 Share on other sites More sharing options...
Kzisor Posted January 17, 2015 Share Posted January 17, 2015 (edited) @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 January 17, 2015 by Kzisor Link to comment https://forums.kleientertainment.com/forums/topic/49272-sanity-gain-on-eating-a-certain-food-type/#findComment-603153 Share on other sites More sharing options...
ArashiOtter Posted January 18, 2015 Author Share Posted January 18, 2015 @Kzisor Thank you so very much it works now. Link to comment https://forums.kleientertainment.com/forums/topic/49272-sanity-gain-on-eating-a-certain-food-type/#findComment-603205 Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now