Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvement of the GetInventory function for offline player management and new inventory search features #1787

Open
Mesrine67 opened this issue Aug 29, 2024 · 3 comments
Labels
enhancement New feature or request

Comments

@Mesrine67
Copy link

Mesrine67 commented Aug 29, 2024

I propose an enhancement to the ox_inventory:GetInventory function so that it works correctly when attempting to retrieve the inventory of an offline player using their citizenid. Currently, the function does not seem to return the inventory as expected in this scenario, limiting the ability to manage critical items (such as keys) for disconnected players. Additionally, I would like to suggest adding a new feature that allows searching for specific items across all existing inventory types.

Identified Issues:

  1. Retrieving inventory for offline players:
    Currently, the ox_inventory:GetInventory function does not allow retrieving the inventory of an offline player via their citizenid, which prevents access to specific items such as rental keys when the player is not connected. This limitation complicates resource and interaction management in the game, especially in contexts where a player’s offline status should not be a hindrance.

  2. Global item search:
    There is currently no simple way to search for a specific item across all inventories, whether they are player inventories (online or offline), vehicle trunks, job stashes, or even temporary containers. This makes it challenging to manage items globally on the server.

Problematic Example Code for Inventory Retrieval:

local function getInventorykeyRentOffline(citizenid, metadata)
    local inventory = ox_inventory:GetInventory({owner = citizenid})
    if inventory then
        local item = ox_inventory:GetItem({
            type = 'player',
            owner = inventory.owner},
            'key',
            metadata,
            false
        )
        if item then
            return true, {
                code = 'getInventoryRentMetadata',
                message = 'Item found successfully',
                item = item
            }
        end
        return true, {code = 'GetInventorykeyRent', message = 'Inventory retrieved:', inventory = inventory}
    else
        return false, {code = 'GetInventorykeyRent', message = 'Error: Inventory not found'}
    end
end

Proper Functioning of getInventorykeyRent:

Note that the getInventorykeyRent function works correctly for online players:

local function getInventorykeyRent(source, metadata)
    local inventory = ox_inventory:GetInventory(source)
    if inventory then
        local item = ox_inventory:GetItem(
             source
            'key',
            metadata,
            false
        )
        if item then
            return true, {
                code = 'getInventoryRentMetadata',
                message = 'Item found successfully',
                item = item
            }
        end
        return true, {code = 'GetInventorykeyRent', message = 'Inventory retrieved:', inventory = inventory}
    else
        return false, {code = 'GetInventorykeyRent', message = 'Error: Inventory not found'}
    end
end

Proposed Enhancements:

  1. Offline Inventory Retrieval:
    I suggest that the ox_inventory:GetInventory function be improved to support the retrieval of offline player inventories using their citizenid. This could include:

    • Automatic loading of offline inventory: If the player is not online, GetInventory should be able to automatically load the inventory from the database or another persistent source.
    • Return of the full inventory: If successful, the function should return the complete inventory, allowing scripts to continue functioning normally, whether the player is online or offline.
  2. Global Item Search:
    I also propose adding a new feature that allows searching for specific items across all existing inventory types (players, stashes, vehicles, etc.). Here’s an idea of the function to be added:

    local function getInventoryByItems(items, filter)
        if type(items) == 'table' then 
            -- Search across multiple items
        else 
            -- Search for a single item
        end
        -- Search through all inventories based on the specified filter
        -- If the filter is empty, search in all types of inventories: 'player' (all/offline/online), 'stash', 'container', 'drop', 'glovebox', 'trunk', 'dumpster'
    end

Expected Benefits:

  1. Simplified management of offline items: Allows for the retrieval, management, and manipulation of items for offline players in a transparent manner.

  2. Improved server functionality: Facilitates the management of critical resources (such as keys) that could otherwise remain inaccessible when players are offline.

  3. Easier global search: Allows administrators and scripts to perform quick and efficient searches across all available inventories on the server.

  4. Gameplay continuity: This functionality ensures continuity in gameplay and inventory systems, avoiding interruptions due to technical limitations.

I hope this suggestion will be considered to improve ox_inventory and offer greater flexibility and better inventory management, particularly in scenarios involving offline players or specific item searches.

@Mesrine67 Mesrine67 added the enhancement New feature or request label Aug 29, 2024
@thelindat
Copy link
Member

#1699

Offline Inventory Retrieval

Requires a lot of changes to be made that would require many ugly workarounds to even maintain compatibility with existing code.

Global Item Search

With the current database design it's would also be horrendous to search for just the inventories with the specified item(s) and load those. Loading every inventory from the database into the resource would also have many issues.

@Mesrine67
Copy link
Author

ok thanks for your reply

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants
@thelindat @Mesrine67 and others