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

[BUG] Inventory dupe items infinitely #403

Closed
SKITTLE6969 opened this issue Dec 23, 2022 · 12 comments
Closed

[BUG] Inventory dupe items infinitely #403

SKITTLE6969 opened this issue Dec 23, 2022 · 12 comments
Labels
bug Something isn't working Stale Closed Stale

Comments

@SKITTLE6969
Copy link

SKITTLE6969 commented Dec 23, 2022

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

@SKITTLE6969 SKITTLE6969 added the bug Something isn't working label Dec 23, 2022
@ihr-it-projekt
Copy link

ihr-it-projekt commented Dec 27, 2022

@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
Copy link

i have created a pull request
#406

@SKITTLE6969
Copy link
Author

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
Copy link

Okay, this is another issue then i have.

@i-kulgu
Copy link

i-kulgu commented Dec 30, 2022

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
Copy link
Author

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

@nzkfc
Copy link
Contributor

nzkfc commented Jan 5, 2023

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
Copy link
Author

SKITTLE6969 commented Jan 5, 2023

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
Copy link
Contributor

nzkfc commented Jan 13, 2023

Follow this method,

Holy shit! It actually works ><

@SKITTLE6969
Copy link
Author

Follow this method,

Holy shit! It actually works ><

told ya heheeee xD

@Leksap
Copy link

Leksap commented Apr 12, 2023

any update on this?

@github-actions
Copy link

github-actions bot commented Oct 5, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Stale Closed Stale
Projects
None yet
Development

No branches or pull requests

5 participants