zUsername Posted January 18, 2016 Share Posted January 18, 2016 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 More sharing options...
DarkXero Posted January 18, 2016 Share Posted January 18, 2016 (edited) With this you can now use Warly's inst.components.eater.getsanitymultfn = getmultfn inst.components.eater.gethungermultfn = getmultfn inst.components.eater.gethealthmultfn = getmultfn I attach. for_modmain.lua Edited January 18, 2016 by DarkXero Link to comment Share on other sites More sharing options...
zUsername Posted January 18, 2016 Author Share Posted January 18, 2016 2 hours ago, DarkXero said: With this you can now use Warly's inst.components.eater.getsanitymultfn = getmultfn inst.components.eater.gethungermultfn = getmultfn inst.components.eater.gethealthmultfn = getmultfn I attach. for_modmain.lua Thanks you very much. Link to comment Share on other sites More sharing options...
DarkXero Posted January 18, 2016 Share Posted January 18, 2016 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 More sharing options...
zUsername Posted January 19, 2016 Author Share Posted January 19, 2016 (edited) 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 January 19, 2016 by zUsername Link to comment Share on other sites More sharing options...
Muche Posted January 19, 2016 Share Posted January 19, 2016 (edited) 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 January 19, 2016 by Muche wow, this new editor is, *ehm* Link to comment Share on other sites More sharing options...
zUsername Posted January 20, 2016 Author Share Posted January 20, 2016 (edited) 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 January 20, 2016 by zUsername Link to comment Share on other sites More sharing options...
Muche Posted January 20, 2016 Share Posted January 20, 2016 1 hour ago, zUsername said: So any ideas? Does we have onstore event? Thanks in advance. Searching components/container.lua for PushEvent found several events, of them itemget looks promising. Link to comment Share on other sites More sharing options...
zUsername Posted January 20, 2016 Author Share Posted January 20, 2016 (edited) Thanks @DarkXero and @Muche . Edited January 21, 2016 by zUsername Link to comment 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