[DISCONTINUED] esx-kr-bag-inventory

I tried your version but I still cant see the bags after restarting. I imported your sql (after clearing the previous one), and also my server and client cache.
Any idea what is wrong here?

After server restart they appear. But if you restart client they disappear (sometimes)
:slight_smile:
I have 5 restarts every 24h so really not a problem for me atm.

I might look into it more, just maybe. Since it isn’t really a problem atm

1 Like

Note, if you drop it it’s no longer yours :slight_smile:

Also if it takes time for your client to spawn (because many scripts or slow server) increase citizen.wait.

RegisterNetEvent('esx:playerLoaded')
AddEventHandler('esx:playerLoaded', function(xPlayer)

    Citizen.Wait(5000) --increase this to load bags later

    PlayerData = xPlayer

    ESX.TriggerServerCallback('esx-kr-bag:getAllBags', function(bags)
        if bags ~= nil then
            for i=1, #bags, 1 do
                TriggerEvent('esx-kr-bag:SpawnBagIntoClient', bags[i].x, bags[i].y, bags[i].z)
                TriggerEvent('esx-kr-bag:insertIntoClient', bags[i].id)
                
                
            
            end
        end

        ESX.TriggerServerCallback('esx-kr-bag:getBag', function(bag)
            if bag ~= nil then
                BagId = bag.bag[1].id
                HasBag = true
                TriggerEvent('esx-kr-bag:SetOntoPlayer')

            end
        end)
    end)
end)

Hi, I would like to know if it was possible to relate the bag inventory with the second inventory from the esx_inventoryhud script and if so how thanks

Hello,

I’m using cui_character [CleanUI cui_character] has my skin and identity system, I also have esx_skin and skinchanger. But whenever I try to equip, pick or drop a bag it sets my skin as default, if anyone can help I would be much appreciated.

Thanks for your time
Lambrusco

i have no option to “use” the item any help we have the sql set up but no use

I NEED HELP!
When i go to my database to add the bag to the shop, i only have 25 items and that’s it. How do i get the bag and other items onto my database?

If I don’t want any weapons in my bag What do i have to do

1 Like

Hey, i did not see your message

Yea i miss wrote :slight_smile: do you only have 25 items in items table or in shops table?

You can search google on how to do sql stuff and add items etc.

hey managed to make this work, the only thing that doesnt work is the search feature when its on the floor

1 Like

I’ve made some modifications to @Heady20006’s modifications.
esx-kr-bag-inventory.zip (9.4 KB)

  1. Added locales nl. and en.
  2. Fixed bag searching
  3. Fixed weird bug where reconnecting while carrying bag disables pickup and searching
  4. Fixed bags not showing up on playerloaded by delaying it, it’s currently on 20000 ms. You can shorten this to match your server.

client > main.lua > line 56
Citizen.Wait(20000)

  1. If blackmoney is showing up as bank balance?

client > main.lua > line 402
Change [1] to the corresponding account (db > users > accounts)
e.g. {“black_money”:0,“bank”:50000,“money”:1000} > blackmoney is [1]

if (PlayerData.accounts[1].money > 0) and (Config.Black == true) then
				table.insert(elements, {
					label     = _U('black')..' ('..PlayerData.accounts[1].money..')',
					count     = PlayerData.accounts[1].money,
					type  = 'blackmoney',
				})
			end

Problems:
I commented out the option to store weapons in the bag and replaced it with a custom weapon-as-item resouce since esx was doing something weird with loadout in my case.
If you want to try fixing it, search for weapons and uncomment the comments.

1 Like

If someone added the weapons to @Kobe_Lamote version, it would be perfect tho!

@Kristian9 I didn’t originally put the weapons script in there because it is made partly in the es_extended script directly and it isn’t perfect. However if you would like to use it, here you go.

THIS WILL NOT WORK OUT OF THE BOX, I’ve tried to explain all needed steps underneath.
esx_weapons.zip (1.6 KB)

This script will acquire people to use the gun/ammo in their inventory before they actually get it. The changes done to es_extended is to remove the weapon from ped when they drop or give it. I know this isn’t perfect but it is a working replacement for the weapons bug.

This script currently is only for 1 weapon, you can easily add weapons by just duplicating it. Script is also explained in comments.

  1. Add to your esx database > items > “glock17” and “glockmagazine”
  2. ensure/start in server.cfg and if you’ve changed the db item names above, change it in the script aswell
  3. Go to es_extended > server > main.lua

under RegisterNetEvent(‘esx:giveInventoryItem’)
under if type == ‘item_standard’ then
under if targetXPlayer.canCarryItem(itemName, itemCount) then
add >

if sourceItem == 'glock17' then
					TriggerClientEvent('removecombatpistol', -1)
				end

it should look like this

RegisterNetEvent('esx:giveInventoryItem')
AddEventHandler('esx:giveInventoryItem', function(target, type, itemName, itemCount)
	local playerId = source
	local sourceXPlayer = ESX.GetPlayerFromId(playerId)
	local targetXPlayer = ESX.GetPlayerFromId(target)

	if type == 'item_standard' then
		local sourceItem = sourceXPlayer.getInventoryItem(itemName)

		if itemCount > 0 and sourceItem.count >= itemCount then
			if targetXPlayer.canCarryItem(itemName, itemCount) then
				sourceXPlayer.removeInventoryItem(itemName, itemCount)
				targetXPlayer.addInventoryItem   (itemName, itemCount)

				sourceXPlayer.showNotification(_U('gave_item', itemCount, sourceItem.label, targetXPlayer.name))
				targetXPlayer.showNotification(_U('received_item', itemCount, sourceItem.label, sourceXPlayer.name))
				if sourceItem == 'glock17' then
					TriggerClientEvent('removecombatpistol', -1)
				end
			else
				sourceXPlayer.showNotification(_U('ex_inv_lim', targetXPlayer.name))
			end
		else
			sourceXPlayer.showNotification(_U('imp_invalid_quantity'))
		end
	elseif type == 'item_account' then
		if itemCount > 0 and sourceXPlayer.getAccount(itemName).money >= itemCount then
			sourceXPlayer.removeAccountMoney(itemName, itemCount)
			targetXPlayer.addAccountMoney   (itemName, itemCount)

			sourceXPlayer.showNotification(_U('gave_account_money', ESX.Math.GroupDigits(itemCount), Config.Accounts[itemName], targetXPlayer.name))
			targetXPlayer.showNotification(_U('received_account_money', ESX.Math.GroupDigits(itemCount), Config.Accounts[itemName], sourceXPlayer.name))
		else
			sourceXPlayer.showNotification(_U('imp_invalid_amount'))
		end
	elseif type == 'item_weapon' then
		if sourceXPlayer.hasWeapon(itemName) then
			local weaponLabel = ESX.GetWeaponLabel(itemName)

			if not targetXPlayer.hasWeapon(itemName) then
				local _, weapon = sourceXPlayer.getWeapon(itemName)
				local _, weaponObject = ESX.GetWeapon(itemName)
				itemCount = weapon.ammo

				sourceXPlayer.removeWeapon(itemName)
				targetXPlayer.addWeapon(itemName, itemCount)

				if weaponObject.ammo and itemCount > 0 then
					local ammoLabel = weaponObject.ammo.label
					sourceXPlayer.showNotification(_U('gave_weapon_withammo', weaponLabel, itemCount, ammoLabel, targetXPlayer.name))
					targetXPlayer.showNotification(_U('received_weapon_withammo', weaponLabel, itemCount, ammoLabel, sourceXPlayer.name))
				else
					sourceXPlayer.showNotification(_U('gave_weapon', weaponLabel, targetXPlayer.name))
					targetXPlayer.showNotification(_U('received_weapon', weaponLabel, sourceXPlayer.name))
				end
			else
				sourceXPlayer.showNotification(_U('gave_weapon_hasalready', targetXPlayer.name, weaponLabel))
				targetXPlayer.showNotification(_U('received_weapon_hasalready', sourceXPlayer.name, weaponLabel))
			end
		end
	elseif type == 'item_ammo' then
		if sourceXPlayer.hasWeapon(itemName) then
			local weaponNum, weapon = sourceXPlayer.getWeapon(itemName)

			if targetXPlayer.hasWeapon(itemName) then
				local _, weaponObject = ESX.GetWeapon(itemName)

				if weaponObject.ammo then
					local ammoLabel = weaponObject.ammo.label

					if weapon.ammo >= itemCount then
						sourceXPlayer.removeWeaponAmmo(itemName, itemCount)
						targetXPlayer.addWeaponAmmo(itemName, itemCount)

						sourceXPlayer.showNotification(_U('gave_weapon_ammo', itemCount, ammoLabel, weapon.label, targetXPlayer.name))
						targetXPlayer.showNotification(_U('received_weapon_ammo', itemCount, ammoLabel, weapon.label, sourceXPlayer.name))
					end
				end
			else
				sourceXPlayer.showNotification(_U('gave_weapon_noweapon', targetXPlayer.name))
				targetXPlayer.showNotification(_U('received_weapon_noweapon', sourceXPlayer.name, weapon.label))
			end
		end
	end
end)

then

under RegisterNetEvent(‘esx:giveInventoryItem’)
under if type == ‘item_standard’ then
under if itemCount > 0 and sourceItem.count >= itemCount then
under if targetXPlayer.canCarryItem(itemName, itemCount) then
add >

if sourceItem == 'glock17' then
					TriggerClientEvent('removecombatpistol', -1)
				end

It should look like this

RegisterNetEvent('esx:giveInventoryItem')
AddEventHandler('esx:giveInventoryItem', function(target, type, itemName, itemCount)
	local playerId = source
	local sourceXPlayer = ESX.GetPlayerFromId(playerId)
	local targetXPlayer = ESX.GetPlayerFromId(target)

	if type == 'item_standard' then
		local sourceItem = sourceXPlayer.getInventoryItem(itemName)

		if itemCount > 0 and sourceItem.count >= itemCount then
			if targetXPlayer.canCarryItem(itemName, itemCount) then
				sourceXPlayer.removeInventoryItem(itemName, itemCount)
				targetXPlayer.addInventoryItem   (itemName, itemCount)

				sourceXPlayer.showNotification(_U('gave_item', itemCount, sourceItem.label, targetXPlayer.name))
				targetXPlayer.showNotification(_U('received_item', itemCount, sourceItem.label, sourceXPlayer.name))
				if sourceItem == 'glock17' then
					TriggerClientEvent('removecombatpistol', -1)
				end
			else
				sourceXPlayer.showNotification(_U('ex_inv_lim', targetXPlayer.name))
			end
		else
			sourceXPlayer.showNotification(_U('imp_invalid_quantity'))
		end
	elseif type == 'item_account' then
		if itemCount > 0 and sourceXPlayer.getAccount(itemName).money >= itemCount then
			sourceXPlayer.removeAccountMoney(itemName, itemCount)
			targetXPlayer.addAccountMoney   (itemName, itemCount)

			sourceXPlayer.showNotification(_U('gave_account_money', ESX.Math.GroupDigits(itemCount), Config.Accounts[itemName], targetXPlayer.name))
			targetXPlayer.showNotification(_U('received_account_money', ESX.Math.GroupDigits(itemCount), Config.Accounts[itemName], sourceXPlayer.name))
		else
			sourceXPlayer.showNotification(_U('imp_invalid_amount'))
		end
	elseif type == 'item_weapon' then
		if sourceXPlayer.hasWeapon(itemName) then
			local weaponLabel = ESX.GetWeaponLabel(itemName)

			if not targetXPlayer.hasWeapon(itemName) then
				local _, weapon = sourceXPlayer.getWeapon(itemName)
				local _, weaponObject = ESX.GetWeapon(itemName)
				itemCount = weapon.ammo

				sourceXPlayer.removeWeapon(itemName)
				targetXPlayer.addWeapon(itemName, itemCount)

				if weaponObject.ammo and itemCount > 0 then
					local ammoLabel = weaponObject.ammo.label
					sourceXPlayer.showNotification(_U('gave_weapon_withammo', weaponLabel, itemCount, ammoLabel, targetXPlayer.name))
					targetXPlayer.showNotification(_U('received_weapon_withammo', weaponLabel, itemCount, ammoLabel, sourceXPlayer.name))
				else
					sourceXPlayer.showNotification(_U('gave_weapon', weaponLabel, targetXPlayer.name))
					targetXPlayer.showNotification(_U('received_weapon', weaponLabel, sourceXPlayer.name))
				end
			else
				sourceXPlayer.showNotification(_U('gave_weapon_hasalready', targetXPlayer.name, weaponLabel))
				targetXPlayer.showNotification(_U('received_weapon_hasalready', sourceXPlayer.name, weaponLabel))
			end
		end
	elseif type == 'item_ammo' then
		if sourceXPlayer.hasWeapon(itemName) then
			local weaponNum, weapon = sourceXPlayer.getWeapon(itemName)

			if targetXPlayer.hasWeapon(itemName) then
				local _, weaponObject = ESX.GetWeapon(itemName)

				if weaponObject.ammo then
					local ammoLabel = weaponObject.ammo.label

					if weapon.ammo >= itemCount then
						sourceXPlayer.removeWeaponAmmo(itemName, itemCount)
						targetXPlayer.addWeaponAmmo(itemName, itemCount)

						sourceXPlayer.showNotification(_U('gave_weapon_ammo', itemCount, ammoLabel, weapon.label, targetXPlayer.name))
						targetXPlayer.showNotification(_U('received_weapon_ammo', itemCount, ammoLabel, weapon.label, sourceXPlayer.name))
					end
				end
			else
				sourceXPlayer.showNotification(_U('gave_weapon_noweapon', targetXPlayer.name))
				targetXPlayer.showNotification(_U('received_weapon_noweapon', sourceXPlayer.name, weapon.label))
			end
		end
	end
end)
  1. then go to es_extended > client > main.lua
    add (doesn’t really matter where, if you are unsure place it at line 217)
RegisterNetEvent('removecombatpistol')
AddEventHandler('removecombatpistol', function()
	RemoveWeaponFromPed(GetPlayerPed(-1), 1593441988)
end)

(I think you also need to do these steps for putting these items in the bag (to delete weapon from ped) but I haven’t done those yet, I will reply to this message when I do.)
Do all these steps for every weapon.

is it possible to add more than one type of bag ? so players don’t use the same bag it would be a cool implementation

1 Like

when player die, the backpack can be “taken” infinite times, so that makes a bug extreme danger to RP servers (sorry my english)

someone have solve that bug?

Hey there, we have some Issue:
When a Player own a Bag and leave the Server with the Bag still owned, they rejoin as Cayou, Men, Women, both join as Cayou.
We spend a Week in find the Issue, cause first we thought it depends on skin/skinchanger, the DB or something like that.
Yesterday we noticed a Girl always spawning as Cayou with the Bag on.
So we stopped the Script and Tadaaaa: Everybody spawns with their created Char.

Why? How?
It’s a pitty, i wanna use the bag script so hardcore because its so genius.
Is there any solution?

Have a sunny Weekend, Greetz from Germany ^^

Hey we also have that Problem, anyone found a solution?

Nope. We deinstalled it. What a pitty…