Ox_inventory - remove only weapons after death

Hi, i need a help with removing/losing weapons after death. I know there is a config.removeweapons in esx_ambulancejob, but its not working for OX_INVENTORY, because weapons made as items. How to make it works for ox_inventory

yo brother just update your ambulance job
it’s included

could you send link? because i checked the newest esx_ambulacenjob and the RemoveWeaponsAfterDeath is same and its not working for ox_inv.

I made this code for removing/losing weapons after death for ox_inventory.

local rawInventory = exports.ox_inventory:Inventory(source).items
	local inventory = {}
	if Config.RemoveWeaponsAfterRPDeath then
		for _,v in pairs(rawInventory) do
            if v.name:sub(0, 7) == 'WEAPON_' then
                inventory[#inventory + 1] = {
                    v.name,
                    v.count,
                    v.metadata
                }
                exports.ox_inventory:RemoveItem(source, v.name, v.count, v.metadata)
            end
	end
end
if Config.OxInventory then return cb() end
1 Like

Hello I need help on where to put this code at please and thank you

replace this event is esx_ambulancejob/server/main.lua

	-- print("1")
	local xPlayer = ESX.GetPlayerFromId(source)

	local playerLoadout = {}
	-- print("2")
    local rawInventory = exports.ox_inventory:Inventory(source).items
	local inventory = {}
	if Config.RemoveWeaponsAfterRPDeath then
		
		for _,v in pairs(rawInventory) do
            if v.name:sub(0, 7) == 'WEAPON_' then
                inventory[#inventory + 1] = {
                    v.name,
                    v.count,
                    v.metadata
                }
                exports.ox_inventory:RemoveItem(source, v.name, v.count, v.metadata)
            end
		end

	
	else -- save weapons & restore em' since spawnmanager removes them
		for i=1, #xPlayer.loadout, 1 do
			table.insert(playerLoadout, xPlayer.loadout[i])
		end

		-- give back wepaons after a couple of seconds
		CreateThread(function()
			Wait(5000)
			for i=1, #playerLoadout, 1 do
				if playerLoadout[i].label ~= nil then
					xPlayer.addWeapon(playerLoadout[i].name, playerLoadout[i].ammo)
				end
			end
		end)
	end
	if Config.OxInventory then return cb() end	
	if Config.OxInventory and Config.RemoveItemsAfterRPDeath then
		exports.ox_inventory:ClearInventory(xPlayer.source)
		return cb()
	end

	if Config.RemoveCashAfterRPDeath then
		if xPlayer.getMoney() > 0 then
			xPlayer.removeMoney(xPlayer.getMoney())
		end

		if xPlayer.getAccount('black_money').money > 0 then
			xPlayer.setAccountMoney('black_money', 0)
		end
	end

	if Config.RemoveItemsAfterRPDeath then
		for i=1, #xPlayer.inventory, 1 do
			if xPlayer.inventory[i].count > 0 then
				xPlayer.setInventoryItem(xPlayer.inventory[i].name, 0)
			end
		end
	end

	if Config.OxInventory then return cb() end

	

	cb()
end)```