AndRay Posted October 29, 2020 Share Posted October 29, 2020 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 More sharing options...
DecDuck Posted October 29, 2020 Share Posted October 29, 2020 Why not just use a crockpot? Why do you need a completely new type of item? Copy and paste the crockpot.lua in a new file, and change as needed. Link to comment Share on other sites More sharing options...
AndRay Posted October 29, 2020 Author Share Posted October 29, 2020 I actually did not think of that. Good thing I asked. So, what are the files I need to copy as well? (crockpot.lua isn't independent of all the others) Thanks for the suggestion btw Link to comment Share on other sites More sharing options...
DecDuck Posted October 29, 2020 Share Posted October 29, 2020 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 More sharing options...
AndRay Posted October 29, 2020 Author Share Posted October 29, 2020 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 More sharing options...
DecDuck Posted October 29, 2020 Share Posted October 29, 2020 What do you want the modified one to do? What you need to modify depends on what you want to do. Link to comment Share on other sites More sharing options...
AndRay Posted October 29, 2020 Author Share Posted October 29, 2020 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 More sharing options...
DecDuck Posted October 29, 2020 Share Posted October 29, 2020 Do you mean "empty space" as in any filler? You can call AddCookerRecipe to add recipes to crockpots. Link to comment Share on other sites More sharing options...
AndRay Posted October 29, 2020 Author Share Posted October 29, 2020 No, I mean "empty space" as in "if you put anything it doesn't work". The plan is for a prepping station of sorts and so having space makes sense. Link to comment Share on other sites More sharing options...
DecDuck Posted October 29, 2020 Share Posted October 29, 2020 (edited) 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 October 29, 2020 by decduck3 Link to comment Share on other sites More sharing options...
AndRay Posted October 30, 2020 Author Share Posted October 30, 2020 Yeah, that was the idea. Sorry for the delay, got excited and started to code to see what worked. Link to comment Share on other sites More sharing options...
DecDuck Posted October 30, 2020 Share Posted October 30, 2020 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 More sharing options...
AndRay Posted October 30, 2020 Author Share Posted October 30, 2020 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 More sharing options...
DecDuck Posted October 30, 2020 Share Posted October 30, 2020 It may be. You might just need to copy the code from containers.lua, then use that for the crockpot. Link to comment Share on other sites More sharing options...
AndRay Posted October 30, 2020 Author Share Posted October 30, 2020 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 More sharing options...
AndRay Posted October 31, 2020 Author Share Posted October 31, 2020 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 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