Goregonzola Posted February 28, 2021 Share Posted February 28, 2021 (edited) Hey there! I've started working on a new survivor. His main feature would be that he would immediately eat any kind of consumable upon pick-up. I would need some kind of reference for the coding, but I don't really know any kind of similar mechanic in the game like this. How could I approach this? I don't expect a polished coding from you, I would be absolutely fulfilled with a pointing to the right direction (, though, if there's a finished coding on the tip of your tounge, I wouldn't refuse it either). Side-quest: Is there an easy way to make the character restore 5 Hunger whenever he consumes something? Thanks in advance! Have a great day! Edited February 28, 2021 by BillTheCipher Link to comment https://forums.kleientertainment.com/forums/topic/127504-make-survivor-immediately-eat-food-upon-pick-up/ Share on other sites More sharing options...
Combustiblemon Posted February 28, 2021 Share Posted February 28, 2021 1. in pigbrain.lua ~~ if inst.sg:HasStateTag("busy") then return end if inst.components.inventory ~= nil and inst.components.eater ~= nil then local target = inst.components.inventory:FindItem(function(item) return inst.components.eater:CanEat(item) end) if target ~= nil then return BufferedAction(inst, target, ACTIONS.EAT) end end ~~ make function containing this and insert doperiodictask will work I guess Of course 'not edible consumable' like spider glands will not work you have to add them manually. 2. use inst:ListenForEvent("oneat", function) local function HungerPlus(inst, data) if data.food then inst.components.hunger:DoDelta(5) end end inst:ListenForEvent("oneat", HungerPlus) as I said in up consumable that is not edible like spider gland is different, you have to add them manually like AddPrefabPostInit("spider_gland_prefab_name_idk", function_that_do_fill_hunger_if_specific_character_uses_it). Link to comment https://forums.kleientertainment.com/forums/topic/127504-make-survivor-immediately-eat-food-upon-pick-up/#findComment-1433697 Share on other sites More sharing options...
Goregonzola Posted February 28, 2021 Author Share Posted February 28, 2021 @Combustiblemon Many thanks for the codings! Point 2) works flawlessly, but I'm not sure if I use the pig one the right way. Here's how I added it to my prefab: Spoiler -- This went above local function onload(inst): local function Stresseat(inst) if inst.components.inventory ~= nil and inst.components.eater ~= nil then local target = inst.components.inventory:FindItem(function(item) return inst.components.eater:CanEat(item) end) if target ~= nil then return BufferedAction(inst, target, ACTIONS.EAT) end end end -- This went into the local master_postinit = function(inst) section: inst:DoPeriodicTask( 0.0, function(inst) Stresseat(inst) end) Have I managed to mess up something? Link to comment https://forums.kleientertainment.com/forums/topic/127504-make-survivor-immediately-eat-food-upon-pick-up/#findComment-1433743 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