Jump to content

OnCook Event?

Recommended Posts

Hello Community!


Im new to the Dont Starve modding scene and would like to know if there is a kind of Listener,

that i can use to execute an event when something is cooked.


Thx for your help!

Link to comment
Share on other sites

Unfortunately, there is no event for that. You'd have to do something like:

local function OnSomethingCooked(cooked_thing, cooker)   -- your code hereendAddComponentPostInit("stewer", function(component, inst)    -- delay a frame so that the component can get initialized by the prefab    inst:DoTaskInTime(0, function()        -- save the old callback function if it exists        local ondonecooking_base = component.ondonecooking or function() end        component.ondonecooking = function(cooker)            ondonecooking_base(cooker)            OnSomethingCooked(component.product, cooker)        end    end)end)
Link to comment
Share on other sites

but its possible to override StartCooking and do something like


function Stewer:StartCooking()oldStartCooking(self)self.inst:DoTaskInTime(self.targettime-GetTime()+0.1, function() self.inst:PushEvent("stew",{product=self.product},GetWorld()) end)end
its not completed code, just an idea, there must be onload/onsave handlers and its boring

i guess much better to intercept ondonecooking something like:

function Stewer:StartCooking()self.oldondonecooking = self.ondonecooking or nilself.ondonecooking = function()self.inst:PushEvent("stew",{product=self.product},GetWorld())if self.oldondonecooking then self:oldondonecooking() endendoldStartCooking(self)end
Link to comment
Share on other sites


This topic is now archived and is closed to further replies.

Please be aware that the content of this thread may be outdated and no longer applicable.

  • Create New...