Jump to content

SetAbsorptionModifiers Eater Components


Recommended Posts

I want to make a character like Warly from DSS, but I have a problems with SetAbsorptionModifiers.


SetAbsorptionModifiers only effect on the second times I eat food.


Thanks in advanced.

Here is my scripts:

local function OnEat(inst, food) 
	local mult = 1
	if food.components.edible then
		if food:HasTag("preparedfood") then
			mult = 1.2
		elseif food.prefab:find("cooked") then
			mult = 1
		elseif food.prefab:find("dried") then
			mult = 0.9
		elseif not food.prefab:find("dried") and not food.prefab:find("cooked") then
			mult = 0.8
		end
	end	
    inst.components.eater:SetAbsorptionModifiers(mult, mult, mult)
end

local master_postinit = function(inst)
	inst.components.eater:SetOnEatFn(OnEat)
end


 

 

 

Link to comment
Share on other sites

50 minutes ago, zUsername said:

Thanks you very much.

For the record, your method would work with this on master_postinit

local _Eat = inst.components.eater.Eat
inst.components.eater.Eat = function(self, food)
	OnEat(self.inst, food)
	return _Eat(self, food)
end

Overriding the Eat function to apply the modifiers before eating.

 

The issue with this would be, for example, that the sanity multiplier would affect the negative sanity buff when eating spoiled food.

That doesn't happen with Warly though, Warly's multiplier affects the sanity for fresh food.

Link to comment
Share on other sites

19 hours ago, DarkXero said:

For the record, your method would work with this on master_postinit


local _Eat = inst.components.eater.Eat
inst.components.eater.Eat = function(self, food)
	OnEat(self.inst, food)
	return _Eat(self, food)
end

Overriding the Eat function to apply the modifiers before eating.

 

The issue with this would be, for example, that the sanity multiplier would affect the negative sanity buff when eating spoiled food.

That doesn't happen with Warly though, Warly's multiplier affects the sanity for fresh food.

Wonderful. Thanks you very much.
Can I ask you some questions?

1. How to check items can be pick up? I can't find "canpickupfn" in DST.

2. I have a problems when making Portable Cookpot. It's crashes when I press "Cook" with local cooktime = nil.

And one more thing: When I move mouse to Portable Cookpot it's show "Store" instead of "Cook".
Here is my code:

local function fn(Sim)

    inst:AddComponent("stewer")
    inst.components.stewer.onstartcooking = startcookfn
    inst.components.stewer.oncontinuecooking = continuecookfn
    inst.components.stewer.oncontinuedone = continuedonefn
    inst.components.stewer.ondonecooking = donecookfn
    inst.components.stewer.onharvest = harvestfn
    inst.components.stewer.onspoil = spoilfn
        
    inst:AddComponent("container")
    inst.components.container:WidgetSetup("cookpot")

end

Thanks you.

And here is my log:


 

 

log.zip

Edited by zUsername
Link to comment
Share on other sites

11 hours ago, zUsername said:

1. How to check items can be pick up? I can't find "canpickupfn" in DST.

2. I have a problems when making Portable Cookpot. It's crashes when I press "Cook" with local cooktime = nil.

And one more thing: When I move mouse to Portable Cookpot it's show "Store" instead of "Cook".

1. According to componentactions.lua, PICKUP action availability is evaluated based on inventoryitem component:

inventoryitem = function(inst, doer, actions)
	if inst.replica.inventoryitem:CanBePickedUp() and doer.replica.inventory ~= nil and 
		not (inst:HasTag("catchable") or inst:HasTag("fire")) then
		table.insert(actions, ACTIONS.PICKUP)
	end
end,

2. From components/stewer.lua:

local cooktime = 1
self.product, cooktime = cooking.CalculateRecipe(self.inst.prefab, ings)

cooktime = TUNING.BASE_COOK_TIME * cooktime

It seems this assumes that cooking.CalculateRecipe() always returns valid product (I guess that's what wet goop is for).

Have you added recipes for your cooker with AddCookerRecipe?

3. From componentactions.lua:

stewer = function(inst, doer, actions, right)
    if not inst:HasTag("burnt") then
        if inst:HasTag("donecooking") then
            table.insert(actions, ACTIONS.HARVEST)
        elseif right and
            (inst:HasTag("readytocook")
            or (inst.replica.container ~= nil and
                inst.replica.container:IsFull() and
                inst.replica.container:IsOpenedBy(doer))) then
            table.insert(actions, ACTIONS.COOK)
        end
    end
end,

From components/stewer.lua:

local function oncheckready(inst)
    if inst.components.container ~= nil and
        not inst.components.container:IsOpen() and
        inst.components.container:IsFull() then
        inst:AddTag("readytocook")
    end
end

From this I'd guess your cookpot wasn't full?

Edited by Muche
wow, this new editor is, *ehm*
Link to comment
Share on other sites

7 hours ago, Muche said:

1. According to componentactions.lua, PICKUP action availability is evaluated based on inventoryitem component:


inventoryitem = function(inst, doer, actions)
	if inst.replica.inventoryitem:CanBePickedUp() and doer.replica.inventory ~= nil and 
		not (inst:HasTag("catchable") or inst:HasTag("fire")) then
		table.insert(actions, ACTIONS.PICKUP)
	end
end,

2. From components/stewer.lua:


local cooktime = 1
self.product, cooktime = cooking.CalculateRecipe(self.inst.prefab, ings)

cooktime = TUNING.BASE_COOK_TIME * cooktime

It seems this assumes that cooking.CalculateRecipe() always returns valid product (I guess that's what wet goop is for).

Have you added recipes for your cooker with AddCookerRecipe?

3. From componentactions.lua:


stewer = function(inst, doer, actions, right)
    if not inst:HasTag("burnt") then
        if inst:HasTag("donecooking") then
            table.insert(actions, ACTIONS.HARVEST)
        elseif right and
            (inst:HasTag("readytocook")
            or (inst.replica.container ~= nil and
                inst.replica.container:IsFull() and
                inst.replica.container:IsOpenedBy(doer))) then
            table.insert(actions, ACTIONS.COOK)
        end
    end
end,

From components/stewer.lua:


local function oncheckready(inst)
    if inst.components.container ~= nil and
        not inst.components.container:IsOpen() and
        inst.components.container:IsFull() then
        inst:AddTag("readytocook")
    end
end

From this I'd guess your cookpot wasn't full?

Thanks you very much. Problems 2 solved with AddCookerRecipe.
I'm still stuck in with problems 1. If I use components.inventoryitem, I can't make cookpot auto open when I put item into because in actions.lua we have:
 

            if act.target.components.inventoryitem == nil then
                act.target.components.container:Open(act.doer)
            end

So any ideas?  Does we have onstore event? Thanks in advance.

Edited by zUsername
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...