MF99K Posted June 2, 2016 Share Posted June 2, 2016 I thought this would be fairly straight forward, but the functions I made either didn't do anything or made that game crash. anyone have a suggestion as to what should work I'm assuming a listenforevent would be hungerdelta but I'm not sure. Link to comment https://forums.kleientertainment.com/forums/topic/67848-prevent-character-from-eating-when-full/ Share on other sites More sharing options...
CarlZalph Posted June 2, 2016 Share Posted June 2, 2016 20 minutes ago, mf99k said: I thought this would be fairly straight forward, but the functions I made either didn't do anything or made that game crash. anyone have a suggestion as to what should work I'm assuming a listenforevent would be hungerdelta but I'm not sure. AddPrefabPostInit("wilson", function(inst) if(inst and inst.components and inst.components.eater and inst.components.hunger) then local Eat_old = inst.components.eater.Eat inst.components.eater.Eat = function(self, food, feeder) if(inst.components.hunger:GetPercent()==1.0) then return false end if(Eat_old~=nil) then return Eat_old(self, food, feeder) end return true end end end ) By returning false here the player will try doing the animation and make sounds but state that they can't do it. To make the player completely not eat with animations and everything you'd need to edit the SGWilson. AddStategraphPostInit("wilson", function(sg) if(sg and sg.actionhandlers and sg.actionhandlers[GLOBAL.ACTIONS.EAT] and sg.actionhandlers[GLOBAL.ACTIONS.EAT].deststate) then local deststate_old = sg.actionhandlers[GLOBAL.ACTIONS.EAT].deststate sg.actionhandlers[GLOBAL.ACTIONS.EAT].deststate = function(inst, action) if(inst and inst.prefab=="wilson") then local obj = action.target or action.invobject if(obj and obj.components and obj.components.edible) then if(inst.components and inst.components.hunger) then if(inst.components.hunger:GetPercent()==1.0) then inst:PushEvent("wonteatfood", { food = obj }) return end end end end return deststate_old(inst, action) end end end ) Which will make it play the disgusted animation. Though I'd probably change GetPercent()==1.0 to be a threshold like GetPercent()>=0.95 since the hunger by default will drain frequently making the percentile go down. Link to comment https://forums.kleientertainment.com/forums/topic/67848-prevent-character-from-eating-when-full/#findComment-779101 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