How to design an item (and inventory) system for a game

Hello, I’m trying to create a sort of RPG/adventure game. I’m currently brainstorming on how inventory would work in this game, but I’m realizing that I have no idea how to even begin with a good, standardized item system, and how to connect them to how the items are used.

I don’t really have a problem thinking about how I would organize items in an inventory; I’ll figure that out later. My main issue at the moment is I don’t know how to standardize what items would even be in the first place. There would be a lot of different types of items and different items per type, and some of them would have gameplay uses. I just don’t know how to start thinking about how to relate an item classification system to actual functional uses those items would have.

In short: I want ideas on how to create an item classification system like Minecraft.

2 Likes

I would suggest simply classifying items by using OOP or some similar system to OOP, where you define each type of item as its own class/class-like thing (idk, you could simulate OOP via tables). Then, simply access the values of the class when organizing the actual inv.

For example, you write a class called cake, which says that it can stack up to 16 times, can be equipped on the head, and perhaps some custom things you can do to it (such as “consume” or something). Now, when the player gets a cake, you go check and find that they can store up to 16 times, so if there is already a stack of cake in the inventory which contains less than 16 cakes, you add a cake to that. (Probably just add a integer that signifies the amount of items in a slot). If there is more, you go find the next stack. If there is no non-full stack, you create a new one at the first empty inventory slot.

Inventory slots could use tables, where a table stores n slots each able to have its own “type of thing stored” and “amount of things stored”. You can then just modify specific parts of the table to achieve adding, removing, or moving objects in the inventory.

Rendering the inventory could be achieved by simply sending the information of a specific player’s inventory to their client, and then having the client create UI objects that signify each slot of the inventory, with images on them that shows what item is stored there.

If you want, I could show you an example of a basic inventory which I’ve created, although its not exactly elegantly written.

1 Like

You basically want to check if the item the player is picking up already exists in the player’s inventory. Every frame that displays the item the player is holding should have either an attribute or a value representing the number of item it stores. Ex:
Lets say you pick up a wood plank, then you want to check if the frame representing the storage of that item already exists:

local inventoryframe = script.Parent.InventoryFrame
function AddToFrame(item)
   if not inventoryframe:FindFirstChild(item.Name) then
      -- Make and display the frame of the new item
   else
      local itemframe = inventoryframe:FindFirstChild(item.Name)
      itemframe.AmountValue.Value += 1
      itemframe.AmountLabel.Text = tostring(itemframe.AmountValue.Value)
   end
end)
item.PickUp:Connect(AddToFrame)
1 Like

If I understand correctly, you’re saying I should emulate a class for each type of item? Wouldn’t that be a LOT of classes? I’m also happy to look at what you’ve made.

1 Like

Well, I’m thinking that I should probably create a central organized system for all the items in my game. Because of the type of game it is, there would be quite a variety of items. My issue isn’t that I don’t know how to interpret picking up items into the inventory; I’ll handle that later. What I’m worried about first is classifying the items.

1 Like

Well, you don’t have to emulate it for each, but you could likely write out some sort of class-like system in which each type of item has a few certain pre-sets (maybe just a bunch of objects would work actually lol)

I personally used 3 tables, where one of them stored the amount of items that can be stacked for each type, one for what can be equipped, and one for what can be worn

That’s what i’m doing:

module.define(
	"Knife",
	"A handy knife, good for basic attacks and I can harvest meat with it",
	{5,20},
	{"Rock,50"},
	950
)

module.define(
	"BlowDart",
	"A BlowDart! It allows me to be effective from a far distance",
	{10,15},
	{"Feathers,25","Fiber,25","Rock,15","Wood,40"},
	2500
)

module.define(
	"WoodHelmet",
	"A helmet made out of wood. It can block a % of incoming damage.",
	{1,5},
	{"Wood,100","IronBar,2"},
	2500
)

module.define(
	"WoodArmor",
	"Armor made out of Wood. It can block a % of incoming damage.",
	{1,10},
	{"Wood,200","IronBar,5"},
	2500
)

Along with other helper methods for the module. As you can see, i have definitions for it, like the damage modifier, the crafting required modifier, and the sell price of the item.

3 Likes

Usually I work on basic inventory without any function, first of all i make ItemData module in replicated storage where i can add new items and change their propertiess/type

Using data stores and folder structure i make inventory, it saves ect. also i make drop/pick script that can detects when to call module called Item, you can add aditional modules to use those types, for example if item is tool it can have Tool class that allows it to be used or throwed or anything

? why can’t you add it to the table? custom function makes no sense, it’s overcomplication