How to make an inventory

I have no idea where to start. I’ve looked at other gamemodes with it, but it’s too confusing. I have 2 files:

cl_inventory obviously makes the vgui for it.
inventory is stuff for it.
I know that you need stuff in init too, but I don’t know what to do.
I want it to save locally, which means with txt files, not mysql or sqllite.
This is not a request, I would just like somoene to point me in the direction for what I need to do.



is most you need, use glon to save the table to files and load them
use usermessages to send it
and obviously derma for the menu

Ok, one question. What would I use the tables for?

To put the items on maybe? The floor works too if you can’t use tables.

You need the tables to manage the inventory for each player. Something like this:
YourInventoryAddonName = {}
YourInventoryAddonName.Players = {}
YourInventoryAddonName.Players[playerid] = {}

Repeat the last line for every player and add new inventory items to the player’s table. This is probably the best way if you don’t want anything too complicated like a trading system or something like that.

Ok, will try to make this. Would it be different stuff since i’m making this for a gamemode, not an addon?

It doesn’t matter. The “YourInventoryAddonName” is just for grouping the inventory functions into a single table. If you don’t need that, you can always save the inventory’s player table as a global variable. (You should probably rename it to something more descriptive though…)

I was going to use file.Write for saving… Is that ok too?

Im no expert but wouldent that be easy to “hack” so you could put anything in your inventory by editing the text file

Yes because he is going to be saving it on the client

The text file is saved on the server so clients don’t have a file they can edit.

You need GLON to write a table to a string that you can save with file.Write.

Well, I have a copy of another gamemode called RE2, and the creator of that doesn’t use GLON, and he uses file.Write.

You can use whatever you like better. Glon just makes saving data easier but you can also devise your own system for writting and saving that data.

If you use GLON, you can just do
local inventorysavestring = glon.encode(InventoryPlayerTable)
file.Write(“inventoryfile.txt”, inventorysavestring)

There are other ways to turn a table into a string, but they would result in larger files and often don’t support certain types of data.

Actually due to it’s nature of conserving every table index intact glon might be too good for the job and save superfluous data. It’s a great tool but it’s always better to do things yourself if you want to optimize things as best as possible. Just saying.