how would I check if the player has two of Stone? I know I could check their inventory for it, but how would I know I’m looking for stone? I thought of maybe getting the name of the key, but it seems like that isn’t possible, and I feel like giving every material it’s own name is wayyy to excessive
What’s the alternative? Usually games will have a unique ID for every item in the game so that it’s easy to identify and reference them.
From the code you posted, if the key values in the Recipe table are the unique IDs, you could just use those when checking the player’s inventory.
local RequiredItems = crafting_recipes.Engineering.sharpstone.Recipe
local Inventory = ... -- Whatever inventory system you're using
for ItemId, RequiredAmount in RequiredItems do
if not Inventory:Contains(ItemId, RequiredAmount) then
-- Player doesn't have all the items for the recipe
end
end
It sounds like you need to implement some type of inventory system for the player because this could be done with some simple calls to that system. Something like the following
local PlayerInventory = Inventories[Player] -- Some way to grab the player's inventory
-- If this returns 0, they don't have the item in their inventory at all.
-- If it's anything less than the recipe requires, they don't have the right amount
local ItemCount = PlayerInventory:GetCount(RequiredItem)
You can design the interface for that however you feel is best.
You put the item ID in the recipe itself so you immediately know which IDs are part of the recipe
Recipe = {["Sharp Stone"] = 2, Stick = 1}
Looking at this, we know that Sharp Stone and Stick are part of the recipe. We don’t need to go through every ID in the game and cross check it with this recipe.