Skip to content

feat(server/functions): add RegisterInventory - #636

Closed
t1ger-scripts wants to merge 1 commit into
qbcore-framework:mainfrom
t1ger-scripts:main
Closed

feat(server/functions): add RegisterInventory#636
t1ger-scripts wants to merge 1 commit into
qbcore-framework:mainfrom
t1ger-scripts:main

Conversation

@t1ger-scripts

Copy link
Copy Markdown

Description

This PR introduces a new function, RegisterInventory, which ensures that inventories loaded from the database are fully initialized with the correct metadata (label, maxweight, and slots).

Currently, qb-inventory only loads items and isOpen when restoring inventories from the database during server startup. This means that any script interacting with a stash before it has been opened at least once will encounter issues, because maxweight, slots, and label are still nil until OpenInventory runs. This results in errors during weight checks or item insertion, especially for stashes created by external resources on startup or server restarts.

RegisterInventory resolves this by:

Creating the inventory if it does not exist

Updating/normalizing metadata for existing inventories using supplied values or Config.StashSize defaults

Mirroring the behavior of InitializeInventory and metadata setup inside OpenInventory

This provides a proper initialization path for third-party scripts (e.g., job systems, mechanic scripts, stash generators) to ensure inventories are fully usable immediately after registration, even before a player opens them.

A new export (RegisterInventory) is included so external resources can safely register or update stashes in a consistent, officially supported way.

This change is fully backwards compatible and does not modify existing DB structure or stash creation workflows.

Checklist

  • [x ] I have personally loaded this code into an updated qbcore project and checked all of its functionality.
  • [x ] My code fits the style guidelines.
  • [ x] My PR fits the contribution guidelines.

This PR introduces a new function, RegisterInventory, which ensures that inventories loaded from the database are fully initialized with the correct metadata (label, maxweight, and slots).

Currently, qb-inventory only loads items and isOpen when restoring inventories from the database during server startup. This means that any script interacting with a stash before it has been opened at least once will encounter issues, because maxweight, slots, and label are still nil until OpenInventory runs. This results in errors during weight checks or item insertion, especially for stashes created by external resources on startup or server restarts.

RegisterInventory resolves this by:

Creating the inventory if it does not exist

Updating/normalizing metadata for existing inventories using supplied values or Config.StashSize defaults

Mirroring the behavior of InitializeInventory and metadata setup inside OpenInventory

This provides a proper initialization path for third-party scripts (e.g., job systems, mechanic scripts, stash generators) to ensure inventories are fully usable immediately after registration, even before a player opens them.

A new export (RegisterInventory) is included so external resources can safely register or update stashes in a consistent, officially supported way.

This change is fully backwards compatible and does not modify existing DB structure or stash creation workflows.
@github-actions

Copy link
Copy Markdown

This PR has had 60 days of inactivity & will close within 7 days

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants