LGF Inventory
Common
Server Exports

Server Exports

Confiscate Inventory

  • This function checks whether a specific player's inventory has been confiscated.
--- Checks if a player's inventory is confiscated
-- @param target number The player's ID
-- @return boolean Returns true if the inventory is confiscated, otherwise false
exports.LGF_Inventory:isInventoryConfiscated(target)

Force Close Inventory

  • This function forces an inventory to close for a player.
--- Forces an inventory to close for a player.
-- @param target number The player's ID
exports.LGF_Inventory:forceCloseInventory(target)

Is Inventory Full

  • This function checks whether a player's inventory is full, based on the weight limit.
--- Checks if the inventory is full based on weight
-- @param target number The player's ID
-- @return boolean Returns true if the inventory is full (exceeds weight limit)
exports.LGF_Inventory:isInventoryFull(target)

Get Item Count

  • This function retrieves the count of a specific item in a player's inventory.
--- Retrieves the count of a specific item in a player's inventory.
-- @param target number The ID of the player.
-- @param itemName string The name of the item.
-- @return number The quantity of the item possessed by the player.
exports.LGF_Inventory:getItemCount(target, itemName)

Fetch Inventory Data

  • This function fetches the inventory data of a player.
--- Fetches the inventory data of a player.
---@param typeInventory string Inventory type ("player", "drops", "dumpsters", "shop")
---@param value number|string ID or identifier of the inventory
---@return table|boolean Inventory data or false if an error occurs
 exports.LGF_Inventory:getInventoryData(typeInventory, value)

Find First Available Free Slot

  • This function finds the first available free slot in a player's inventory.
--- Finds the first available free slot in a player's inventory.
-- @param target number The ID of the player.
-- @return number The index of the first free slot.
exports.LGF_Inventory:getFirstFreeSlot(target)

Add Item

  • This function adds an item to a player's inventory.
--- Adds an item to a player's inventory.
-- @param target number The ID of the player.
-- @param itemName string The name of the item to add.
-- @param quantity number The amount of the item to add.
-- @param slot? number|nil Specific slot to add the item from (optional)
-- @param metadata? table|nil Additional item metadata (optional)
-- @return boolean True if the item was added successfully; false otherwise.
exports.LGF_Inventory:addItem(target, itemName, quantity, metadata, slot)

Remove Item

  • This function removes an item from a player's inventory.
--- Removes an item from a player's inventory.
-- @param target number The ID of the player.
-- @param itemName string The name of the item to remove.
-- @param quantity number The amount of the item to remove.
-- @param slot? number|nil Specific slot to remove the item from (optional)
-- @param metadata? table|nil Additional item metadata (optional)
-- @return boolean True if the item was removed successfully; false otherwise.
exports.LGF_Inventory:removeItem(target, itemName, quantity, metadata, slot)

Get Inventory Weight

  • This function retrieves the total weight of a player's inventory.
--- Retrieves the total weight of a player's inventory.
-- @param target number The ID of the player.
-- @return number The total weight of the inventory.
local totalWeight = exports.LGF_Inventory:getInventoryWeight(target)

Clear Inventory

  • This function clears all items from a player's inventory.
--- Clears all items from a player's inventory.
-- @param target number The ID of the player.
-- @return boolean True if the inventory was cleared successfully; false otherwise.
local success = exports.LGF_Inventory:clearInventory(target)

Open Target Inventory

  • This function opens the inventory of a target player. Requires Ace permissions "lgf_inventory.openTargetInventory".
--- Opens the inventory of a target player. Required Ace perms "lgf_inventory.openTargetInventory"
-- @param source number The ID of the player initiating the action.
-- @param target number The ID of the target player whose inventory is to be opened.
-- @return boolean True if the inventory was opened successfully; false otherwise.
local success = exports.LGF_Inventory:openTargetInventory(source, target)

Confiscate Inventory

  • This function confiscates the inventory of a target player. It can also return the confiscated inventory based on the action parameter.
--- Confiscates the inventory of a target player.
-- @param target number The ID of the player whose inventory is to be confiscated.
-- @param action string "confiscate" to confiscate the inventory target or "add" to return a confiscated inventory.
-- @return boolean True if the inventory was confiscated successfully; false otherwise.
local success = exports.LGF_Inventory:confiscateInventory(target, action)

Has Item

  • This function checks if a player has a specific item in their inventory.
--- Checks if a player has a specific item in their inventory.
-- @param target number The ID of the player.
-- @param itemName string The name of the item to check for.
-- @param quantity number|nil The quantity to check.
-- @return boolean True if the player has the item; false otherwise.
local hasItem = exports.LGF_Inventory:hasItem(target, itemName, quantity)

Set Metadata

  • This function sets metadata for a specific item in a player's inventory.
--- Sets metadata for a specific item in a player's inventory.
-- @param target number Player ID
-- @param data table Table containing item information (itemName, metadata, slot)
-- @return boolean success Indicates if the operation was successful
-- @return string response Contains details about the operation result
local success, response = exports.LGF_Inventory:setMetadata(target, data)

Get Player Items

  • This function retrieves the inventory of a specific player.
--- Retrieves the inventory Items of a specific player.
-- @param target number The ID of the player whose inventory is to be retrieved.
-- @return table A table containing the player's inventory items.
exports.LGF_Inventory:getPlayerItems(target)

Register Server Hook

  • This function registers a server-side hook for a specific inventory event. It triggers a callback when the event occurs.
--- Registers a server-side hook for a specific inventory event.
-- @param eventType string The type of event to hook into (e.g., 'itemAdded', 'move').
-- @param callback function The function to be called when the event occurs.
-- @return string The ID of the Hook
local id = exports.LGF_Inventory:registerServerHook(eventType, function(eventData) end)

Remove Server Hook

  • This function removes a previously registered server-side hook for a specific inventory event.
--- Removes a previously registered server-side hook.
-- @param eventType string The type of event for which the hook was registered.
-- @param id string The ID of the Hook
exports.LGF_Inventory:removeServerHook(eventType, id)

Load Inventory

  • This function loads or unloads a player's inventory based on the provided boolean value.
--- Loads a player's inventory.
-- @param target number The ID of the player whose inventory is to be loaded.
-- @param load boolean Whether to load (true) or unload (false) the player's inventory.
-- @return void
exports.LGF_Inventory:loadInventory(target, load)

Transfer Item

  • This function transfers an item from one player to another.
--- Transfers an item from one player to another.
-- @param from_source number The source player ID.
-- @param to_targetId number The target player ID.
-- @param itemName string The name of the item.
-- @param quantity number The amount of the item to transfer.
-- @param metadata table|nil Metadata for the item (optional).
-- @param slot number|nil Slot for the item (optional).
-- @return boolean True if the item was successfully transferred; false otherwise.
exports.LGF_Inventory:transferItem(from_source, to_targetId, itemName, quantity, metadata, slot)

Register Shop

  • This function registers a shop for in-game transactions, including items and restrictions.
--- Registers a shop for in-game transactions.
-- @param shopName string The name of the shop (e.g., `"General Store"`).
-- @param data table The shop details, which should include:
-- @param data.id string A unique identifier for the shop (e.g., `"general_store"`).
-- @param data.items table A list of items the shop sells. Each item is represented as:
-- @param data.items.name string The name of the item (e.g., `"water"`).
-- @param data.items.price number The price of the item in in-game currency (e.g., `100`).
-- @param data.restrictionJobs table|false (optional) A table defining job-based restrictions for the shop:
-- @param data.restrictionJobs.JobName string The job role required to access the shop (e.g., `"police"`).
-- @param data.restrictionJobs.MinGrade number The minimum grade required for that job (e.g., `2`).
-- @param data.restrictionJobs false Set to `false` if no job restrictions are needed.
-- @param data.maxWeight number (optional) The maximum weight that the shop can manage (defaults to 100).
-- @param data.maxSlots number (optional) The maximum number of items the shop can manage (defaults to the number of items in `items`).
-- @return boolean success Indicates if the shop registration was successful.
-- @return string response Contains details about the operation result.
local success, response = exports.LGF_Inventory:registerShop(shopName, data)

Example Register Shop

local success, message = exports.LGF_Inventory:registerShop("general_store", {
    shopName= "GeneralStore",
    items = {
        { name = "water",               price = 33 },
        { name = "burger",              price = 33 },
        { name = "WEAPON_CARBINERIFLE", price = 1000 },
        { name = "ammo-rifle2",         price = 200 },
    },
    restrictionJobs = {
        { JobName = "police", MinGrade = 2 }
    }
})

Get Money Count

  • This function retrieves the total money count of a player based on a specified type of money (e.g., "money", "black_money", etc.).
--- Retrieves the money count of a player based on the type of money.
-- @param target number Player ID
-- @param type string Type of money ("money", "black_money", etc.)
-- @return number Returns the amount of the specified money type the player has in their inventory
local moneyCount = exports.LGF_Inventory:getMoneyCount(targe, type)

Set Durability

  • This function reduce the durability of a specific item in a player's inventory.
  • The specified valueToReduce will be subtracted from the item's current durability.
  • If the durability reaches 0, it will not go below that value.
  • If the slot is not provided, the function match the metadata object
--- reduce the durability of a specific item in a player's inventory.
-- @param target number The ID of the player.
-- @param itemName string The name of the item to update.
-- @param metadata table|nil Additional metadata for the item (optional).
-- @param slot number|nil The slot of the item (optional).
-- @param valueToReduce number The amount to subtract from the current durability.
-- @return boolean success Indicates if the operation was successful.
-- @return string response Provides details about the operation result.
local success, response = exports.LGF_Inventory:setDurability(target, itemName, metadata, slot, valueToReduce)

Priority Rules

  • metadata: If the slot parameter is not provided (i.e., nil), the function will search for the item based on metadata alone. Therefore, if slot is not specified, metadata must contain enough information to identify the item uniquely.

  • slot: If the slot parameter is provided, it will take priority to find the item, even if there are multiple items with the same itemName but different slots. In this case, metadata is optional and can be omitted.

  • Both (metadata and slot): If both metadata and slot are provided, the function will use both to identify the specific item in the inventory.

  • Neither (metadata nor slot): If neither metadata nor slot are provided, the function cannot accurately identify the item and will return an error or warning.

Example Set Durability

RegisterCommand("testDurability", function(source)
 
    local weaponData = exports.LGF_Inventory:getWeaponData() 
    
    if weaponData and weaponData.metadata and weaponData.metadata.Durability then
        local slot = weaponData.slot
        local metadata = weaponData.metadata
        local itemName = weaponData.itemName
        local durability = metadata.Durability
        local value = 10
 
        print(("Old Durability %s for item in slot %s"):format(durability, slot))
 
        local success, message, newValue = exports.LGF_Inventory:setDurability(1, itemName, metadata, slot, value)
 
        if success then
            print(("New Durability %s for item in slot %s"):format(newValue, slot))
        else
            print(("Error: %s"):format(message))
        end
    end
end)

Get Weapon Data

  • This function retrieves the data for a weapon equipped, including its attributes such as durability, ammo count, rarity, description, and more.
--- Retrieve the data of a weapon item from the inventory
-- @return table weaponData Returns a table containing the weapon data
-- Example structure:
-- {
--    durability: number,
--    stackable: boolean,
--    closeOnUse: boolean,
--    metadata: {
--        CurrentAmmo: number,
--        Durability: number,
--        Serial: string
--    },
--    itemRarity: string,
--    itemLabel: string,
--    itemName: string,
--    throwItem: boolean,
--    itemWeight: number,
--    itemType: string,
--    slot: number,
--    description: string,
--    typeAmmo: string,
--    quantity: number
-- }
exports.LGF_Inventory:getWeaponData()

Register Crafting

  • This function registers a new crafting recipe in the inventory system.
--- Registers a new crafting recipe.
-- @param craftingId string Crafting ID.
-- @param data table Crafting data (including required items and crafting duration).
-- @return boolean success Indicates whether the registration was successful.
-- @return string message Result message of the registration.
local success, message = exports.LGF_Inventory:registerCrafting(craftingId, data)

Example Register Crafting

local success, message = exports.LGF_Inventory:registerCrafting("bench_001", {
    itemsToCraft = {
        ["water"] = {
            DurationCrafting = 30,
            ItemsRequired = {
                { itemName = "water", quantity = 5 },
            }
        },
        ["burger"] = {
            DurationCrafting = 10,
            ItemsRequired = {
                { itemName = "water",  quantity = 5 },
                { itemName = "burger", quantity = 5 },
            }
        }
    }
})

Register Temporany Stash

  • This function registers a new Temporany Stash .
--- Registers a new temporary stash.
-- @param inventoryId string The unique identifier for the stash inventory. Must be a non-empty string.
-- @param data table The data related to the stash, including:
--   - inventoryName (string): The name of the stash inventory.
--   - items (table): A table of items to be added to the stash. Each item should be a table with:
--     - name (string): The name of the item (must be registered).
--     - quantity (number): The quantity of the item.
--   - maxWeight (number, optional): The maximum weight capacity of the stash (default is 100).
--   - maxSlots (number, optional): The maximum number of slots for the stash (default is the number of items provided).
-- 
-- @return boolean success Indicates whether the stash registration was successful.
-- @return string response Contains a message with the result of the registration process. If unsuccessful, the reason is provided.
local success, response = exports.LGF_Inventory:registerTemporanyStash(inventoryId, data)
 

Example Register Stash

local success, response = exports.LGF_Inventory:registerTemporanyStash("stash_001", {
    inventoryName = "Player Stash",
    items = {
        { name = "water", quantity = 10 },
        { name = "burger", quantity = 5 },
        { name = "money", quantity = 1000 }
    },
    maxWeight = 50,  
    maxSlots = 20  
})
print(success, response)

Delete Temporany Stash

  • This function Delete a Temporany Stash by id .
--- Removes a temporary stash.
-- @param inventoryId string The unique identifier for the stash inventory to be removed.
-- @return boolean success Indicates whether the stash removal was successful.
-- @return string response A message containing the result of the removal process.
local success, response = exports.LGF_Inventory:deleteTempStash(inventoryId)