How can i register a usable item

how can i register a usable item

The above response is very poor for this community, sorry your first post had to have a reply with minimalistic information…

The first step is to add the item to the Database.
Screenshot_6

If you havnt already made a server script for handling items, you can use esx_basicneeds/server/main.lua open that up and it should look like this.

You will now see the standard items like Bread and Water, if you are adding a drink, copy the water function or if you adding food you could copy the bread function…

	ESX.RegisterUsableItem('**PUT ITEM ID HERE**', function(source)
		local xPlayer = ESX.GetPlayerFromId(source)
		xPlayer.removeInventoryItem('**PUT ITEM ID HERE**', 1) --This removes the item from the players inventory

		TriggerClientEvent('esx_status:add', source, 'thirst', 200000) --This is how much Thirst/Hunger the item will give the player, change 'thirst' to 'hunger'
		TriggerClientEvent('esx_basicneeds:onDrink', source) -- This plays the animation, so if its a drink your adding keep it as 'onDrink' otherwise change it to 'onEat'
		xPlayer.showNotification("~b~You drank a ~y~McDonalds ~b~ Drink.") --This is the notification that displays when you consume the item, you can use colours like ~b~ = blue ~y~ = yellow ~g~ = green, ect.
	end)

If you use the above code make sure to remove **PUT ITEM ID HERE** and replace it with your item ID that is listed in the database, make sure also to keep your item id in between the ’ ’ s .

Your basicneeds/server/main.lua should look something like this now:

Save Restart basicneeds or Restart your server and there you go, you now have a Usable item.

All the best and welcome to the community!

11 Likes

I have been doing this all day but everytime I restart the server it disappears from the server.lua?

2 Likes

Hmm that doesnt even make sence, addons should never get automatically modified, after stopping/starting the server, unless your modifying the cache files and not the recource files, or are the files somehow linked up to github and being updated and reverted back to the standard version upon stopping the server?

Please provide more information as I have never had a addon change its own code after stopping the server.

2 Likes

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