Hi everyone,
here is a quick tutorial on how to add items which you can eat and drink in FiveM Esx framework.
First you need to add an item which you will eat or drink to the items table in your database. Depending on esx version which you are currently using sql can vary i.g. if you are useing version 1.0 this sql can be used:
INSERT INTO items
(name
, label
, limit
, rare
, can_remove
) VALUES
(‘hotdog’, ‘Hot Dog’, 10, 0, 1);
This sql query adds a Hot Dog item to the table. Player can carry max. 10 items and items can be removed from the inventory.
Perfect, we have added an item, now we need to register this item as usable in esx_basicneeds resource.
Go to esx_basicneeds/server/main.lua and add following:
ESX.RegisterUsableItem('hotdog', function(source)
local xPlayer = ESX.GetPlayerFromId(source)
xPlayer.removeInventoryItem('hotdog', 1)
TriggerClientEvent('esx_status:add', source, 'hunger', 200000)
TriggerClientEvent('esx_basicneeds:onEat', source)
TriggerClientEvent('esx:showNotification', source, _U('used_hotdog'))
end)
We have registered an item wich will add value of 200000 to our huger stat.
And as a last part of the process you need to add a new variable/ text to the language file in the esx_basicneeds/locales folder so you have a message after you have used/eat/drink an item. In our case Hot Dog
['used_hotdog'] = 'you have used ~y~1x~s~ ~b~Hot Dog~s~',
So.. that would be eat. Restart server an go eat some Hot Dogs 😉
If you need FiveM Gameserver with one click installation check this:
https://zap-hosting.com/rpscripts
20% discount if you want: denmak-a-6883
If you need some general Fivem help, you can take a look at this Discord server:
https://discord.gg/Bdk3QHX