Server editable.lua

function calcTotalWeight(player, items)
    if config.tgiannServer then 
        local totalWeight = exports["qb-inventory"]:GetTotalWeight(player.PlayerData.items)
        local playerInventoryData = exports["qb-inventory"]:getPlayerInventoryData(player.PlayerData.source)
        local weight = 0
        for slot, itemData in pairs(items) do
            weight = weight + itemData.weight * itemData.amount
        end
        if (totalWeight + weight) <= playerInventoryData.maxweight then
            return true
        else
            return false
        end

    elseif config.framework == "qb" then
        local totalWeight = exports["qb-inventory"]:GetTotalWeight(player.PlayerData.items)
        local weight = 0
        for slot, itemData in pairs(items) do
            weight = weight + itemData.weight * itemData.amount
        end
        if (totalWeight + weight) <= config.MaxInventoryWeight then
            return true
        else
            return false
        end

    elseif config.framework == "esx" then
        local oxExport = exports.ox_inventory
        local playerItems = oxExport:GetInventoryItems(player.source)
        local weight = 0
        for slot, itemData in pairs(playerItems) do
            weight = weight + itemData.weight * itemData.count
        end
        local canCarryWeight, freeWeight = oxExport:CanCarryWeight(player.source, weight)
        if freeWeight == 0 then
            return false
        else
            return true
        end

    end
end

function getPlayerItems(player) 
    if config.framework == "qb" then
        return player.PlayerData.items
    elseif config.framework == "esx" then
        return exports.ox_inventory:GetInventoryItems(player.source)
    end
end

function getItemBySlot(player, slot)
    return tgiCore.getItemBySlot(player, slot)
end

function addItem(player, data, slot)
    if config.framework == "qb" then
        tgiCore.addItem(player, data.name, data.amount, slot, data.info)
    elseif config.framework == "esx" then
        tgiCore.addItem(player, data.name, data.count, slot, data.metadata)
    end
end

function removeItem(player, data)
    return tgiCore.removeItem(player, data.name, data.amount, data.slot)
end

Last updated