Add Item

A function which adds item to a player. How you can adapt the function for other framework example.

VORP

SConfig.AddItem = function(source, item, amount, type)
    local VORPInv = exports.vorp_inventory
    if type == "item" then
        local itemCheck = VORPInv:getItemDB(item)
        local canCarry = VORPInv:canCarryItems(source, amount)       --can carry inv space
        local canCarry2 = VORPInv:canCarryItem(source, item, amount) --cancarry item limit

        if not itemCheck or not canCarry or not canCarry2 then
           return false
        end

        VORPInv:addItem(source, item, amount)
    elseif type == "weapon" then
        local canCarry = VORPInv:canCarryWeapons(source, amount, nil, item)
        if canCarry then
            return false
        end
        local result = VORPInv:createWeapon(source, item, {})
        if not result then
            return false
        end
    end
    return true
end

QBCore

SConfig.AddItem = function(source, item, amount, type)
    local Player = QBCore.Functions.GetPlayer(source)
    if not Player then return false end
    if not Player.Functions.AddItem(item, amount) then
        return false
    end
    return true
end

Last updated

Was this helpful?