Making water give you empty bottles

Hello i wanted to ask if someone has an idea how i can make it so if i drink water that i get an empty bottle from it which then has the function to be refilled i use ox_inventory and ive already tryed adding this code in esx_optionalneeds but that didnt worked out:

ESX.RegisterUsableItem('water', function(source)
	local xPlayer = ESX.GetPlayerFromId(source)

	xPlayer.removeInventoryItem('water', 1)

	TriggerClientEvent('esx_status:add', source, 'thirst', 350000)
	TriggerClientEvent('esx_optionalneeds:onDrink', source)

	Citizen.Wait(0)
	xPlayer.addInventoryItem('empty_bottle', 1)
end)

this is the item which is inside my inventory:

    ['water'] = {
		label = 'Wasser',
		weight = 50,
        stack = true,
		close = true,
		client = {
            status = { thirst = 350000 },
            anim = { dict = 'mp_player_intdrink', clip = 'loop_bottle' },
            prop = { model = 'prop_ld_flow_bottle', pos = vec3(0, 0, 0), rot = vec3(5.0, 5.0, -180.5) },
            usetime = 7500,
        },
    },

   ['empty_bottle'] = {
		label = 'Leere Flasche',
		weight = 3,
		stack = true,
		close = true,
	},
1 Like

The source might be gone when you call the addInventoryItem I guess, the code itself seems like it should work fine

do you have any idea of how i can fix that

Find examples, it’s a fairly common issue

idk if im too dumb but it still doesnt works ive tryed it over and over again but i cant find out why it wont give me the empty bottle

You’ve tested with only the single water bottle in your inventory, then using that item? ox inventory checks weights is why I’m asking if you can not receive the item it will not provide it.

ive created all items i needed the weight is not that big / i have enought space thats why i need help

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.