qbcore-framework / qb-inventory

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

[BUG] Inventory dupe items infinitely #403

Closed SKITTLE6969 closed 10 months ago

SKITTLE6969 commented 1 year ago

Summary

im using all qb latest stuff and qb inventory with a reskin not lj inventory xD

Reproduction

https://streamable.com/b827jw - follow the video new link https://streamable.com/bwj7ah

Expected behavior

WATCH THE VIDEO FOR BETTER UNDERSTANDING

Actual behavior

WATCH THE VIDEO FOR BETTER UNDERSTANDING

Additional context

WATCH THE VIDEO FOR BETTER UNDERSTANDING

Last Updated

couple of days back

Custom Resources

nope

Resource Rename

nope

ihr-it-projekt commented 1 year ago

@SKITTLE6969 Video is not available. But i have the same problem. If you split an item in several stacks and you remove all items in on RemoveItem call without a slot number, then the items will not removed. After a short view in code. I found the reason for. There is no code implemented if a slot has a lower amount of items. So no items will return. See: https://github.com/qbcore-framework/qb-inventory/blob/main/server/main.lua#L255

The code has to change like:


local function RemoveItem(source, item, amount, slot)
    local Player = QBCore.Functions.GetPlayer(source)

    if not Player then return false end

    amount = tonumber(amount) or 1
    slot = tonumber(slot)

    if slot then
        if Player.PlayerData.items[slot].amount > amount then
            Player.PlayerData.items[slot].amount = Player.PlayerData.items[slot].amount - amount
            Player.Functions.SetPlayerData("items", Player.PlayerData.items)

            if not Player.Offline then
                TriggerEvent('qb-log:server:CreateLog', 'playerinventory', 'RemoveItem', 'red', '**' .. GetPlayerName(source) .. ' (citizenid: ' .. Player.PlayerData.citizenid .. ' | id: ' .. source .. ')** lost item: [slot:' .. slot .. '], itemname: ' .. Player.PlayerData.items[slot].name .. ', removed amount: ' .. amount .. ', new total amount: ' .. Player.PlayerData.items[slot].amount)
            end

            return true
        elseif Player.PlayerData.items[slot].amount == amount then
            Player.PlayerData.items[slot] = nil
            Player.Functions.SetPlayerData("items", Player.PlayerData.items)

            if Player.Offline then return true end

            TriggerEvent('qb-log:server:CreateLog', 'playerinventory', 'RemoveItem', 'red', '**' .. GetPlayerName(source) .. ' (citizenid: ' .. Player.PlayerData.citizenid .. ' | id: ' .. source .. ')** lost item: [slot:' .. slot .. '], itemname: ' .. item .. ', removed amount: ' .. amount .. ', item removed')

            return true
        end
    else
        local slots = GetSlotsByItem(Player.PlayerData.items, item)
        local amountToRemove = amount

        if not slots then return false end

        local itemAmountOfPlayer = 0
        for _, _slot in pairs(slots) do
            itemAmountOfPlayer += Player.PlayerData.items[_slot].amount
        end

        if amount > itemAmountOfPlayer then
            return false
        end

        for _, _slot in pairs(slots) do
            if Player.PlayerData.items[_slot].amount > amountToRemove then
                Player.PlayerData.items[_slot].amount = Player.PlayerData.items[_slot].amount - amountToRemove
                Player.Functions.SetPlayerData("items", Player.PlayerData.items)

                if not Player.Offline then
                    TriggerEvent('qb-log:server:CreateLog', 'playerinventory', 'RemoveItem', 'red', '**' .. GetPlayerName(source) .. ' (citizenid: ' .. Player.PlayerData.citizenid .. ' | id: ' .. source .. ')** lost item: [slot:' .. _slot .. '], itemname: ' .. Player.PlayerData.items[_slot].name .. ', removed amount: ' .. amount .. ', new total amount: ' .. Player.PlayerData.items[_slot].amount)
                end

                return true
            elseif Player.PlayerData.items[_slot].amount == amountToRemove then
                Player.PlayerData.items[_slot] = nil
                Player.Functions.SetPlayerData("items", Player.PlayerData.items)

                if Player.Offline then return true end

                TriggerEvent('qb-log:server:CreateLog', 'playerinventory', 'RemoveItem', 'red', '**' .. GetPlayerName(source) .. ' (citizenid: ' .. Player.PlayerData.citizenid .. ' | id: ' .. source .. ')** lost item: [slot:' .. _slot .. '], itemname: ' .. item .. ', removed amount: ' .. amount .. ', item removed')

                return true
            elseif Player.PlayerData.items[_slot].amount < amountToRemove then
                amount -= Player.PlayerData.items[_slot].amount
                local removedAmount -= Player.PlayerData.items[_slot].amount
                Player.PlayerData.items[_slot] = nil
                Player.Functions.SetPlayerData("items", Player.PlayerData.items)

                if not Player.Offline then
                    TriggerEvent('qb-log:server:CreateLog', 'playerinventory', 'RemoveItem', 'red', '**' .. GetPlayerName(source) .. ' (citizenid: ' .. Player.PlayerData.citizenid .. ' | id: ' .. source .. ')** lost item: [slot:' .. _slot .. '], itemname: ' .. item .. ', removed amount: ' .. removedAmount .. ', item removed')
                end
            end
        end
    end
    return false
end

(Code is not tested)

But this is only a dirty fix, maybe someone of QB-inventory owner can fix the code.

ihr-it-projekt commented 1 year ago

i have created a pull request https://github.com/qbcore-framework/qb-inventory/pull/406

SKITTLE6969 commented 1 year ago

since the video is not available all you have to do is open a stash anywhere drop all the items you need to dupe close stash open the stash again and take all the items back while keeping the inventory open f8 quit

once you rejoin all the items will be duplicated even unique items

ihr-it-projekt commented 1 year ago

Okay, this is another issue then i have.

i-kulgu commented 1 year ago

since the video is not available all you have to do is open a stash anywhere drop all the items you need to dupe close stash open the stash again and take all the items back while keeping the inventory open f8 quit

once you rejoin all the items will be duplicated even unique items

I have tested this out and not happening on my side.. did you made changes to your inventory ?

SKITTLE6969 commented 1 year ago

dont try it on a local host, try on a vps server or a different hosting

nzkfc commented 1 year ago

I've tried this on my live server with 120 pop right now, steps:

  1. Spawned 3 pistols on me
  2. Opened apartment stash
  3. Moved 3 pistols in and exited the stash
  4. Re-opened stash and moved 3 pistol to inventory
  5. Press F8 and quit
  6. Rejoined server
  7. 3 pistols in my inventory, none in stash

Does not seem like this exists?

SKITTLE6969 commented 1 year ago

I've tried this on my live server with 120 pop right now, steps:

  1. Spawned 3 pistols on me
  2. Opened apartment stash
  3. Moved 3 pistols in and exited the stash
  4. Re-opened stash and moved 3 pistol to inventory
  5. Press F8 and quit
  6. Rejoined server
  7. 3 pistols in my inventory, none in stash

Does not seem like this exists?

Follow this method, this was done on a vanilla install https://streamable.com/bwj7ah

nzkfc commented 1 year ago

Follow this method,

Holy shit! It actually works ><

SKITTLE6969 commented 1 year ago

Follow this method,

Holy shit! It actually works ><

told ya heheeee xD

Leksap commented 1 year ago

any update on this?

github-actions[bot] commented 10 months ago

This issue has had 60 days of inactivity & will close within 7 days