December 2020
Posted 4 years ago
It's important to me that we don't make assumptions about which games will be made with s&box. I shouldn't hardcode a HL2 style slot and bucket inventory system and expect every game to use it.

So I looked at how the inventory system worked in Source 1 and broke it down into a generic system that can be easily adapted into a bunch of different scenarios.

Every entity has a Inventory member, which is null by default.
attribute 'contenteditable' not allowedattribute 'blocktype' not allowedattribute 'data-image-style' not allowed
If it's not null, when the entity gets a new child, or a child is removed, it tells the inventory about it.
attribute 'contenteditable' not allowedattribute 'blocktype' not allowedattribute 'data-image-style' not allowed
So now whichever class you set as your inventory is in charge of this logic. I've coded a simple inventory class that I'm guessing will meet 90% of people's needs, but all that code is addon side, so you can look at it, derive from it or just make your own class.

The inventory system is responsible for two primary things.. keeping a list of entities in the player's inventory and handling the active entity. The Active entity is the one which is in your hands, the one that is selected.