Jump to content

How do I look through the recipe list for individual items?


Recommended Posts

Hello fellow modders and DST players,

I'm wondering how I would look through the recipe list from the file, Recipes.lua

Instructions:

  1. Read recipes file.
  2. Read through recipe list for entries with science/magic level 1.
  3. Return a list of the recipe names for each entry.

Step 4 I can do on my own, but I'll explain for context. I need to return all the recipes that use a certain station level so I can add the recipe to my character's knowledge. Why am i doing this in such a specific way?

I want to make it so my character has the equivalent of Wickerbottom's knowledge of first level of crafting (Plus for magic), except requires the respective second station for further recipes.

inst:DoTaskInTime(0, function(inst)

inst.components.builder:AddRecipe("shovel")

inst:PushEvent("unlockrecipe", { recipe = "shovel" })

end)

If you can help with this, I'd be extremely grateful. :)

Edited by neahxx
Link to comment
Share on other sites

The table "AllRecipes" (declared in scripts/recipe.lua) stores every declared crafting recipe. In a Recipe object, the Recipe.level variable contains a table of the recipe's (no idea what these are called) tech levels. Here's what I used to find out what the shovel recipe's level variable contains:
image.png.a9e18a5c312cda2e6b474a9b2cd8f10e.png
(printwrap goes through a table and prints out every key and value)

So for your purposes, I imagine you'd have code that looks like this:

 

inst:DoTaskInTime(0, function(inst)
  for k, v in pairs(AllRecipes) do
    if v and v.level and (v.level.SCIENCE == 1 or v.level.MAGIC == 1) then
      inst.components.builder:AddRecipe(v.name)
      inst:PushEvent("unlockrecipe", { recipe = v.name })
      end
  end
end)

I haven't tested it, but if it works it should be compatible with modded recipes as well as vanilla ones.

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