Skip to main content

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:

-- label: string
-- weight: number (optional)
-- stack: boolean (optional) -- If set to false will not allow the item to be stacked
-- degrade: number (optional) -- The amount of time in minutes an item will degrade after
-- close: boolean (optional) -- If set to false will not close the inventory on item use
-- description: string (optional)
-- consume: number (optional) -- Number of an item needed to use it, and removed after use (Default: 1)
-- client: table (optional)
-- buttons: table (optional) -- Allows you to define custom context menu functions for the item

Examples:

['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,
}
}

Making the item usable​

To make an item created in items.lua usable you have define it's functions in the /modules/items/server.lua file.
To do this we use the Item which returns a callback function with event, item, inventory, slot and data params.

event - The event triggering depending on the item action, can be usingItem, usedItem and buyingItem

Example:

Item('testburger', function(event, item, inventory, slot, data)
if event == 'usingItem' then
if Inventory.GetItem(inventory, item, inventory.items[slot].metadata, true) > 0 then
-- if we return false here, we can cancel item use
return {
inventory.label, event, 'external item use poggies'
}
end

elseif event == 'usedItem' then
print(('%s just ate a %s from slot %s'):format(inventory.label, item.label, slot))

elseif event == 'buying' then
print(data.id, data.coords, json.encode(data.items[slot], {indent=true}))
end
end)

Creating container items​

Like with other items the item must first be registered.

Example:

['paperbag'] = {
label = 'Paper Bag',
weight = 1,
stack = false,
close = false,
consume = 0
},

When registered you can define the item as a container under the Items.containers table in /modules/items/sever.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.

['name'] = {
-- size: {slots, maxWeight}
-- slots: number
-- maxWeight: number
-- blacklist: table (optional)
-- ['itemName'] = true
-- whitelist: table (optional)
-- ['itemName'] = true
}

Example:

['paperbag'] = {
size = {5, 1000},
blacklist = {
['testburger'] = true -- No burgers!
}
},