Creating Items
Creating Items
Defining item data
Before being able to see or use an item in game it must first be defined.
All of the items are defined in the /data/items.lua file with key, value pairs. Key is the name (not the label) of an item and the value is a table containing the options for the item.
Item options:
tablelabel:
stringweight?:
numberstack?:
booleanIf set to false will not allow the item to be stacked.
degrade?:
numberAmount of time in minutes the item will degrade after.
decay?:
booleanIf true the item will be deleted when durability reaches 0 (not instant for degraded items).
close?:
booleanIf set to false does not close the inventory on item use.
description?:
stringItem description that will be shown in the tooltip
consume?:
numberItem count needed and removed use.
Default: 1
If set to a decimal will consume durability instead (0.2 = 20%).
allowArmed?:
booleanIf set to true will allow use of item while armed with a weapon.
server?:
tableexport?:
string
client?:
tableexport?:
stringExport to be triggered after item use.
event?:
stringEvent to be triggered after item use.
status?:
tableAdjust esx_status values after use.
anim?:
tableAnimation that will be played during the progress bar.
dict:
stringclip:
string
prop?:
tableAttached prop that will be displayed during the progress bar.
model:
stringorhashpos:
table(x, y, z)rot:
table(x, y, z)bone?:
numberrotOrder?:
number
disable?:
tableActions to be disabled during the progress bar.
move?:
booleancar?:
booleancombat?:
booleanmouse?:
booleansprint?:
boolean
usetime?:
numbercancel?:
booleanIf set to true the player canc cancel item use.
add?:
function(total:number)Function that triggers when receiving an item
Returns total item count as
total
remove?:
function(total:number)Function that triggers when removing an item
Returns total item count as
total
buttons?:
tablelabel:
stringaction:
function(slot:number)Callback function when button is clicked in context menu, returns item slot.
Examples
<Tabs items={["Burger", "Burger with description", "Burger with notification"]}> lua ['burger'] = { label = 'Burger', weight = 220, stack = true, close = true, client = { status = { hunger = 200000 }, anim = { dict = 'mp_player_inteat@burger', clip = 'mp_player_int_eat_burger_fp' }, prop = { model = 'prop_cs_burger_01', pos = { x = 0.02, y = 0.02, y = -0.02}, rot = { x = 0.0, y = 0.0, y = 0.0} }, usetime = 2500, } } A modified burger item which includes a description.
A modified burger item, which gives you notifications on add and remove arguments.
Making the item usable
If you are using ESX, you can continue using
ESX.RegisterUsableItem.If you are using QBox, you can continue using
exports.qbx_core:CreateUseableItem.
Using the built-in system is more secure and provides much more functionality.
Client callbacks
Item callbacks can be added by defining an export (recommended), or by adding it to items/client.lua.
When defining item data, adding client.export will trigger an event on item use. The correct formatting is export = resourceName.exportName.
Server callbacks
A callback function can be defined on the server to handle several events (usingItem, usedItem, buyItem). This can either be an export (recommended), or added to the bottom of items/server.lua. When defining item data, adding server.export will trigger an event for the actions above. The correct formatting is export = resourceName.exportName.
Creating container items
Like with other items the item must first be registered.
When registered you can define the item as a container in /modules/items/containers.lua The key for the container is the name you gave it when registering the item. You can also define the number of slots, the maximum weight, blacklist and whitelist items.
itemName:
slots: number
The number represents the amount of slots
maxWeight: number
The number represents the maximum weight within the container
blacklist:
Supports single and multiple items
{ 'testburger', 'testburger2' }
whitelist:
Supports single and multiple items
{ 'testburger', 'testburger2' }
Example
Last updated