Jump to content

Help with monstermeat food effects


Recommended Posts

So, I've created a custom character, made him be able to eat monstermeat without setting strongstomach to true. The only two problems I'm facing are the speech and sound, I wanted him to just ignore/skip that or just override it with the speech/sound when he eats good food.
This is the code for it:

-- Perk 1local function onEat(inst, food)    if food and food.components.edible then        local food_health = food.components.edible:GetHealth(inst)        local food_hunger = food.components.edible:GetHunger(inst)        local food_sanity = food.components.edible:GetSanity(inst)	        if food:HasTag("monstermeat") then            if food_health < 0 then inst.components.health:DoDelta(math.abs(food_health)) end            inst.components.hunger:DoDelta(math.abs(food_hunger))            if food_sanity < 0 then inst.components.sanity:DoDelta(math.abs(food_sanity)) end        elseif food:HasTag("meat") then            if food_health < 0 then food_health = math.abs(food_health) end            if food_sanity < 0 then food_sanity = math.abs(food_sanity) end		            inst.components.health:DoDelta(food_health)            inst.components.hunger:DoDelta(food_hunger)            inst.components.sanity:DoDelta(food_sanity)        end    endendlocal master_postinit = function(inst)    -- Perk 1 = 1.5 hungerrate    inst.components.hunger.hungerrate = 1.5 * TUNING.WILSON_HUNGER_RATE    inst.components.eater:SetOnEatFn(onEat)end
Link to comment
Share on other sites

I fixed it, incase anyone's interested about how I did it.

I had to rewrite the "Eat" method from Eater and call a function before doing normal Eater:Eat function.

local function beforeEat(food)    if food and food.components.edible then        if food:HasTag("monstermeat") or food:HasTag("meat") then            if food.components.edible.healthvalue < 0 then food.components.edible.healthvalue = 0 end            if food.components.edible.sanityvalue < 0 then food.components.edible.sanityvalue = 0 end        end    endendlocal function onEat(inst, food)    if food and food.components.edible then        local food_health = food.components.edible:GetHealth(inst)        local food_hunger = food.components.edible:GetHunger(inst)        local food_sanity = food.components.edible:GetSanity(inst)            if food:HasTag("meat") then            inst.components.health:DoDelta(food_health)            inst.components.hunger:DoDelta(food_hunger)            inst.components.sanity:DoDelta(food_sanity)        end    endendlocal master_postinit = function(inst)    -- ...    inst.components.eater:SetOnEatFn(onEat)    local self = inst.components.eater    local old = self.Eat    local crockfoods = require("preparedfoods")        function self:Eat(food, force) -- rewriting the Eat event        if crockfoods[food.prefab] then -- test if food is a crockpot food            return old(self, food, force)        end        beforeEat(food)        return old(self, food, force)    end    -- ...end
Link to comment
Share on other sites

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
 Share

×
  • Create New...