OOP Based Tool + Inventory System | 1.0 BETA

Current Version: V.1.0 BETA (07/13/2021)

This is my first post in addition to my portfolio on the forum, constructive criticism is always welcome!

Notable Features

  • Centralized State

  • Absolute control over your tool/inventory objects

  • Easy to grasp and intuitive structure

  • No credits necessary and full help support available!


Introduction

Developers like having absolute control over important aspects of their games which is why I think this system can be a convenient resource. ‘Tools’ and ‘Inventories’ are treated as objects. Each tool is a class extending from the ‘Base’ class that defines some essential events and utilities. The inventory object houses all the tool objects inside it, the client has a copy of its inventory which is kept up-to-date with its server-side counterpart.

https://www.roblox.com/library/7085536353/Inventory-System-1-0-BETA
Package.rbxm (15.3 KB)

OR

Direct download
Inventory-System-1-0-BETA.rbxl (173.9 KB)


How To Use

This is how things are set-up:

Server
    Inventory System
        Tool System
            Tools
                <classes>
            ToolBase <class>
        Inventory System
            InventoryBase <class>
            InventoryService

Client
    Inventory System
        Tool System
            Tools
                <classes>
            ToolBase <class>
        Inventory System
            InventoryBase <class>

To get started, clone the ‘ExampleTool’ module found in the ‘Tools’ folder and start writing your functionality in the ‘Init’ function. To modify what Tools are given when a player spawns, open the ‘InventoryService’ module and edit the ‘StarterPack’ table. More settings for inventories can be configured in the ‘InventoryBase’ module.


Let me know what you think, and please don’t hesitate to post your creations using this module in the replies below!

Click here to read the API

API

InventoryObject InventoryBase.new(Player player)

Creates and returns a new inventory object for the specified player


array InventoryObject:GetClientData()

Returns an array of tools for use by the client

{

{
ID = number, Name = string, Key = string, Storage = boolean } > Key is the KeyCode this tool is equipped/unequipped if it’s in the hotbar. Storage is false if the tool is in the hotbar, false if it’s in ‘Storage’
},

}

number InventoryObject:AddTool(string toolName)

Adds the tool with the specified name to the inventory and returns the added tool’s ID, the Init function of the new tool object is called after it’s added to the inventory

void InventoryObject:RemoveTool(number toolId)

Removes the tool with the specified id, the Destroy function of the found tool is called before it’s removed from the inventory

void InventoryObject:MoveTools(number fromId, number toId)

Swaps the position of the tools with the specified ids

void InventoryObject:EquipTool(string key)

Equips the tool with the specified equip/unequip key, Equipped event of the tool object is fired

void InventoryObject:UnequipTool()

Unequips the currently equipped tool, Unequipped event of the tool object is fired

void InventoryObject:ActivateTool()

Activates the currently equipped tool, Activated event of the tool object is fired


ToolObject ToolBase.new()

Creates and returns a new tool object

Signal ToolObject.Equipped

Fired when the tool is equipped

Signal ToolObject.Unequipped

Fired when the tool is unequipped

Signal ToolObject.Activated

Fired when the holder of the tool presses the LMB

Maid ToolObject.Maid

A utility object for keeping track of cleaning script connections.

void ToolObject:Init()

This function must be present in your tool classes, it is called after the tool is added to an inventory

void ToolObject:Destroy()

This function must be present in your tool classes, it is called before the tool is removed from an inventory


Update Log

Current Version V.1.0 BETA (07/13/2021)
  • Features listed above
Previous Versions & Downloads
36 Likes

Wow!

I’ve gone through this for a bit and I’ve got to say this is really nice. The neat exception of arguments and use of OOP really brings the module out. I always prefer people use these types of modules rather than adding client sided inventory based off from tools in their save folder, or using a server script with a remote or invoke knowing it’s unsecure. This is really really neat and I’d love to look forward to more future contributions by you! Keep doing great work.

4 Likes

Thank you so much for the amazing reply! I really really appreciate it! :grin:

2 Likes

It looks so clean, my god, it’s so aesthetically pleasing lol

2 Likes

How would u use contextactionservice to bind abilities? Example ContextActionService:BindAction("Heavy",Heavy, true, Enum.UserInputType.MouseButton2)

Nice system, clean and straight-forward place to add own implementation.

Noticed client input is sent to the server to fire events before being sent back to the client to fire client-side afterwards. I’m starting to rewrite a few things to activate on the client first for more responsiveness, how come its designed this way and will I break something without realising, or open myself up to another problem?

Thanks