qbcore-framework / qb-inventory

Slot Based Inventory System Used With QB-Core :school_satchel:
GNU General Public License v3.0
53 stars 380 forks source link

Add inventory to cache on creating custom one from other resources. #596

Closed adhershmnair closed 5 days ago

adhershmnair commented 1 week ago

Description

If someone try to create a custom inventory other than stash, glovebox, shop it is currently impossible to add the inventory to existing server inventory cache. Created a new event to add the new inventory to the Inventories cache in server/main.lua file.

Usage in server scripts:

RegisterNetEvent("qb-lockers:openInventory", function(lockerId)
    local src = source
    local InventoryItems = {}
    local lockerInventory = exports["qb-inventory"]:GetInventory(lockerId)
    if (lockerInventory ) then
         InventoryItems = lockerInventory.items
    end
    TriggerEvent("qb-inventory:server:addInventoryToCache", lockerId, InventoryItems )
    exports["qb-inventory"]:OpenInventory(src, lockerId)
end)

This method allows us to add a new inventory, such as QB Lockers, which is a custom inventory, and open it immediately after creating it. Note: Adding the inventory to the database will be handled within the custom inventory's resource.

image

Qwerty1Verified commented 5 days ago

I'm not sure that I think the functionality is needed. A locker is basically just a stash and can act like one when it comes to the way it's handled.

I feel that it opens unnecessary doors, especially with exploiting, to create an event that allows you to set item data.

adhershmnair commented 5 days ago

@Qwerty1Verified Hmm.. So we can use SetInventory export to add the same to Inventories. Right?

image

adhershmnair commented 5 days ago

@Qwerty1Verified Thanks. It worked using SetInventory!!! image

Closing this PR as there was already an export for the same.

Thanks!!!