FiveM Docs
Guides

Add Items

How to add items in ESX Legacy, with the items table SQL, weight, rare and can_remove, ESX.AddItems, usable items via ESX.RegisterUsableItem and ox_inventory notes.

To add an item in ESX Legacy, insert a row into the items table and reload items with /refreshitems (or restart the server). To make the item do something when a player uses it, register a server-side handler with ESX.RegisterUsableItem. If your server runs ox_inventory, items are defined in ox_inventory's own data/items.lua instead and the ESX items table is not used.

Overview

WhatWhere
Item definitions (default inventory)items table
In-memory cacheESX.Items, filled by ESX.RefreshItems() at startup
Reload without restart/refreshitems command
Add items from a scriptESX.AddItems(items)
Use actionESX.RegisterUsableItem(name, cb) (server)
Give an item/giveitem command or xPlayer.addInventoryItem()

Using ox_inventory?

When the ox_inventory resource exists on the server, es_extended switches to ox mode automatically (Config.CustomInventory = 'ox'). In that mode ESX does not read the items table, ESX.RefreshItems and ESX.AddItems are not defined, and the ESX /giveitem and /refreshitems commands are not registered. Follow the ox_inventory guide instead.

The items table

ColumnTypeDefaultDescription
namevarchar(50)Internal item name, primary key. Lowercase, no spaces, for example water.
labelvarchar(50)Display name shown in the inventory.
weightint1Weight per piece. The player's limit is Config.MaxWeight (24 by default).
raretinyint0Stored and passed to the inventory as rare. es_extended itself does not change behavior based on it; UI or third-party scripts may.
can_removetinyint10 blocks dropping and giving the item through the default ESX inventory.

Add an item with SQL

Insert the item

items.sql
INSERT INTO `items` (`name`, `label`, `weight`, `rare`, `can_remove`) VALUES
  ('energy_drink', 'Energy Drink', 1, 0, 1),
  ('lockpick',     'Lockpick',     1, 0, 1),
  ('id_card',      'ID Card',      0, 0, 0);

Use INSERT IGNORE if the script might be installed twice; name is the primary key, so duplicates fail otherwise.

Reload items

In the server console or in game as an admin:

refreshitems

/refreshitems calls ESX.RefreshItems(), which reloads the table and also cleans every online player's inventory: items that no longer exist are removed and the inventory is resent to the client.

Give the item to test it

giveitem 1 energy_drink 5

The arguments are [playerId] [item] [count]; me works as player ID in game. The command validates that the item exists in ESX.Items.

Add items from a script with ESX.AddItems

If your resource needs its own items, register them at runtime so server owners do not have to run SQL.

ESX.AddItems(items)
NameTypeDescription
itemstableList of { name, label, weight?, rare?, canRemove? }. weight defaults to 1, rare to false, canRemove to true.

It skips items that already exist in ESX.Items, validates every field (invalid entries are skipped with a console message), inserts the rest with INSERT IGNORE and refreshes online inventories. There is no return value.

server/items.lua
ESX = exports['es_extended']:getSharedObject()

if ESX.AddItems then -- not defined when ox_inventory is used
    ESX.AddItems({
        { name = 'energy_drink', label = 'Energy Drink', weight = 1 },
        { name = 'id_card', label = 'ID Card', weight = 0, canRemove = false },
    })
end

Make an item usable

Usable items are server-side. When a player uses the item in the default inventory, the client sends esx:useItem; ESX checks that the player actually has at least one, then calls your handler. ESX does not remove the item for you.

ESX.RegisterUsableItem(item, cb)
NameTypeDescription
itemstringItem name from the items table.
cbfunction(source, item, ...)Called with the player's server ID and the item name.
server/items.lua
ESX = exports['es_extended']:getSharedObject()

ESX.RegisterUsableItem('energy_drink', function(source, item)
    local xPlayer = ESX.GetPlayerFromId(source)
    if not xPlayer then return end

    -- Remove first so a fast double-use cannot consume one item twice
    xPlayer.removeInventoryItem(item, 1)
    xPlayer.showNotification('You feel energized!')
    TriggerClientEvent('energy:boost', source, 30000)
end)
client/main.lua
RegisterNetEvent('energy:boost', function(durationMs)
    local playerId = PlayerId()
    SetRunSprintMultiplierForPlayer(playerId, 1.2)
    Wait(durationMs)
    SetRunSprintMultiplierForPlayer(playerId, 1.0)
end)

The handler is wrapped in pcall, so an error in your code prints a warning instead of breaking ESX. Registering an item marks it as usable = true in online players' inventories immediately. ESX.GetUsableItems() returns a table of all registered usable item names, and ESX.UseItem(source, item) lets you trigger the handler yourself.

Official addons follow the same pattern, for example esx_basicneeds (bread, water) and esx_ambulancejob (bandage, medikit).

Work with items in scripts

The most used xPlayer inventory methods:

server/shop.lua
local xPlayer = ESX.GetPlayerFromId(source)

local item = xPlayer.getInventoryItem('lockpick')   -- { name, label, count, weight, usable, rare, canRemove }
if item and item.count >= 1 then
    xPlayer.removeInventoryItem('lockpick', 1)
end

if xPlayer.canCarryItem('energy_drink', 3) then
    xPlayer.addInventoryItem('energy_drink', 3)
else
    xPlayer.showNotification('Your pockets are full')
end

Use ESX.GetItemLabel(name) to show the label of an item, and ESX.GetItems() to get the full item registry.

Starting items

Config.StartingInventoryItems in es_extended/shared/config/main.lua is false by default. Set it to a table of item = count to give new characters items on creation:

es_extended/shared/config/main.lua
Config.StartingInventoryItems = { bread = 2, water = 2 }

It only applies to newly created players, not to existing ones.

ox_inventory note

ox_inventory has its own item list and its own way of handling item use:

  • Define items in ox_inventory/data/items.lua. The ESX items table has no effect while ox mode is active.
  • ESX.Items is filled from ox_inventory's item list, and ESX.GetItemLabel reads from exports.ox_inventory:Items(name).
  • xPlayer.addInventoryItem, removeInventoryItem, getInventoryItem, canCarryItem and hasItem still work; ESX routes them to ox_inventory.
  • ox_inventory can run code on use through its item options (for example a server.export). Check the ox_inventory docs for how it handles items registered with ESX.RegisterUsableItem.

Details and setup order: Using ox_inventory with ESX.

Common issues

Frequently asked questions

Independent documentation

esx-fivem.com is a community project and is not affiliated with the ESX Framework team. Facts on this page were checked against the upstream source. Official resources: docs.esx-framework.org and github.com/esx-framework.
Edit on GitHub

Last updated on

On this page