How to make a crafting system

Ok so first of all i just want to say that i have indeed tried making my own crafting system, im up to the task to script it but i really dont know how i should script it, and by crafting system i mean a botw crafting system where you just plop in a bunch of ingredients onto a pot and nothing else, no fancy slots or anything, i’d like to see people give me suggestions on how to do it since i seem to have no other option than to ask for help in the devforum.

note: i dont use a custom inventory system or anything, and im trying to achieve a system where you throw items into a pot instead of just using ingredients on your inventory and instantly making the desired item without any external help.

3 Likes
2 Likes

i’ve seen both of these posts, none of them helped, plus im not looking for a grid crafting system.

The Second One Tells U Step By Step

i already stated that i dont want a grid crafting system.

Ik A Few Things In There Gives You The Info You Need

as i’ve said, i read both of the posts and they didnt really help me on achieving the crafting system that i want

1 Like

You could have a script inside the pot check for nearby items. Compare those items to a list of allowed items and then if the items are legit recipe items, then check for possible recipe combinations from another list. if there is a hit, then remove those items, and spawn the item that should be crafted.

Is this similar to the crafting system you are going for? No UI involved, just simple part checking within radius of the pot.

well yeah, i could possibly do that but my main problem is that i dont know how to compare recipes with the current ingredients inside of said pot, thats where i’ve been stuck at.

1 Like

Yea that will be tricky. because if there are similar recipes, it might make a different one than intended. One solution is to wait for the player to activate the pot to craft an item that way the pot does not automatically try to craft a different item.

But you could use a checking function that gathers all possible recipes that contains ingredient 1. Then remove from that list all recipes that dont contain ingredient 2. do the same for 3 and any more until you are down to just 1 recipe.

i could do that and it could work, i’ll wait to see if any other solutions pop up and see which would be the best one, thanks anyways.

1 Like

The basics of a crafting system are quite simple. You need the ingredients, and you have to put them in the right place.

I’m not going to make the entire script for you but I’m going to give you a rough idea.

local pot = script.Parent
local recipes = -- Recipies
--[[
    Each recipe would be structured like so:
    {IngredientOne = 1, IngredientTwo = 1}
           ^         ^
      Ingredient  Quantity

    Recipe data can be structured like this:
    {
        ItemOne = {IngredientOne = 1, IngredientTwo = 2}
        ItemTwo = {IngredientOne = 2, IngredientThree = 4}
    }
]]

local potItems = {} -- Table of things stored in a pot

local function CheckRecipe() -- Compare each recipe to each item in the pot to see if any of them matches
    for recipeName, recipe in pairs(recipes) do -- Looping through valid recipes
        local canCraft = true -- This value will determine if you can craft the item
        for ingredient, quantity in pairs(recipe) do
            if potItems[ingredient] ~= quantity then
                canCraft = false -- Oh no! The ingredients aren't quite right!
                break -- Ending this loop to continue on to the next recipe
            end
        end
        if canCraft then -- Checking if the items in the pot has passed all checks
            return recipeName
        end
    end
end

pot.ItemRecieved:Connect(function(item) -- Not an actual function, but you get the idea
    if potItems[item] then -- Checking if the item exists yet
        potItems[item] += 1 -- Adds one
    else
        potItems[item] = 1 --  Creates the item key and index
    end
    CheckRecipe() -- Run a check
end)

pot.ItemRemoved:Connect(function(item) -- Not an actual method, but you get the idea
    potItems[item] -= 1 -- Removing one of this item from the recipe
    if potItems[item] == 0 then
        potItems[item] = nil
        --[[
            Setting it to nil. This will prevent any overlaps in recipes (i.e, some
            recipes would have the same ingredients but with 1 difference)
        --]]
    end
    CheckRecipe() -- Run a check
end)

Quick note that there are some flaws you have to fix yourself, such as the fact that it won’t consider if there are extra items in the pot (if you had a recipe of 3 apples, a pot with 3 apples and 1 pear would still be valid).

12 Likes

alright, i’ll try to fix it myself and see if it works, thanks for the help by the way.
Edit: works like a charm, thanks for the help!

what I like to do for crafting systems is to add a folder into the replicated storage and rename it “Recipes”. Then I would add a folder of the item’s name and add ray int or number values in the folder, rename the int values the materials needed for to make the item. Then change the int values to how much of the certain material is needed. Once that is done you can use a for do loop to grab the materials and test if the player has all the ingredients/materials when they try to craft it

Edit: also I would add a table into a local script for the pot, and the table should have all the ingredients the player is putting into the pot, then grab and check if the ingredients in the table can be crafted into a recipe.

1 Like

the post has already been solved, plus im not looking for a grid based crafting system, appreciate the help though.

In future instead of asking for full systems to be made for you, provide your own work so that it can be fixed/improved, as per the rules of this section.

when did i ever say that i wanted one to be made for me, i just said that i didnt know how to make one due to lack of knowledge, its really not my fault someone decided to be generous and give me an example of how it would be done.

3 Likes