Jump to content

Help with coding a custom crockpot-like prefab?


Recommended Posts

Hey people, I'm new with modding this game and wanted to spice up a bit the game adding a lot of cooking-related stations.

I'd like to code a custom prefab that can cook from a table of recipes, just like the crock pot. I did try and dig a bit around in my mods folder to see how it's done, but got no good examples. Can someone give me some pointers? Thanks in advance!

For a bit of more specific questions, I don't understand what a component is, how to set one properly, and whch functions are essential for it to work. (Also how to set flags like finished cooking, or full, or empty, and set the corresponding animations)

Link to comment
Share on other sites

In the game's code, it's actually called a cookpot. I've just came back from a break of DST modding, and I need to get back into the swing of things.

 

Anyways, you should be able to just copy cookpot.lua in what ever your new crockpot name is.lua. You would need to replace the return Prefab at the end, to change it to your item, but then is should work.(?)

Link to comment
Share on other sites

Ah, okay, makes sense!

I see that I was massively overcomplicating things; I didn't realize the crock pot code was this flexible.

Thanks a lot!

Ah, one more thing: say I want to modify a cooking/crock pot/component function (I'm thinking right now in overriding CalculateRecipe from cooking.lua)

I read in a tutorial once that the way to do this is to get the old function. and then run it as a failsafe, but where do I put the code? Modmain? (And also how to I name it so it actually overrides the desired function?)

Link to comment
Share on other sites

For example, I might want to change the checks for recipes to redirect to the right table (as the game stores all its recipes in a big table) and for stuff like empty spaces on the widget (say corn, empty space, empty space, empty space is a recipe now, it would clash with recipes without empy spaces in priority)

Or I might want to return extra parameters for aiding in more complex recipes.

The CalculateRecipe function has the cooker as one of its arguments so I'm able to special-case my own prefab, right?

Link to comment
Share on other sites

So you want it to be able to cook even if not all the slots are filled? Also to cook from a table of recipes, you make the table, and loop through the entries and called AddCookerRecipe.

Edited by decduck3
Link to comment
Share on other sites

Did anything work?

To allow non-full crockpots, you have to somehow change line 182 in containers.lua:

return inst.replica.container ~= nil and inst.replica.container:IsFull()

To this:

return inst.replica.container ~= nil

I think that will work if nothing else did.

Link to comment
Share on other sites

Yeah, a test recipe got added no problem. AddRecipe is easy enough to use.

So, to allow a closing non-full crock pot you need to change a setting in its widget. I'm guessing it's easier to just setup a near-identical widget then?

Link to comment
Share on other sites

So, I can create an alternative new_cookpot widget no problem, but how can I assign it?

Should I just declare the widget inside the prefab file? Or in modmain and then use it in the prefab file?

I guess the more complete question would be: in which order does the game load mod files?

Link to comment
Share on other sites

Just passing to say that unfortunately the stewer component really does not like empty spaces in it, and throws nil exceptions everywhere, so I will have to code a new component.

But thanks a lot for the help, that allowed me to get to a working prototype so I can start testing stuff!

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...