Skip to content

NPC loot

NPC vehicles (traffic and parked cars of the world, not cars spawned by scripts) carry loot in their real trunk inventory. Player cars never get loot.

  • When: with preload = true, when a player on foot comes within Config.RenderDistance of a parked NPC car, so the props are already in the trunk when it opens, and seen through the windows. Otherwise, the first time the trunk is opened or forced. A car whose trunk already holds something gets no loot.
  • Cars nobody opened are left to the game: when it removes them, their trunk is emptied. A car someone opened or forced stays in the world.
data/loot.lua
SLTrunk.Loot = {
preload = true,
chanceEmpty = 0.35, -- default for tables that do not set it
rolls = { min = 1, max = 3 }, -- default draws from `items`
default = 'common',
classes = { [6] = 'rich', [12] = 'work' }, -- GTA vehicle class -> table
models = { ['myaddoncar'] = 'rich' }, -- model -> table (wins over the class; addon cars go here)
tables = {
rich = {
chanceEmpty = 0.2,
rolls = { min = 1, max = 4 },
always = { -- added every time (chance optional)
{ item = 'phone', chance = 0.5 },
},
items = { -- drawn by weight
{ item = { qb = 'water_bottle', ox = 'water' }, min = 1, max = 2, weight = 20 },
{ item = 'my_addon_item', weight = 5 },
{ item = { qb = 'markedbills' }, weight = 5,
metadata = function(ctx) return { worth = math.random(500, 2500) } end },
{ item = { ox = 'black_money' }, min = 500, max = 2500, weight = 5 },
},
},
},
}
Entry field
item Item name, or { qb = ..., ox = ... } when the inventories name it differently (qs-inventory uses the qb name). Without a name for your inventory the entry is skipped
min, max Amount (default 1)
weight How likely in items (relative; default 1)
metadata ox_inventory metadata / qb-inventory and qs-inventory info: a table, or a function (ctx) returning one
chance In always only: chance it is added (0–1)

ctx is { vehicle, plate, model, class, table }. The same item drawn twice (without metadata) is added once with both amounts. Everything goes through the trunk’s capacity. Items that do not exist on your server are skipped and listed in the console on start.

Vehicle classes: 0 compacts, 1 sedans, 2 SUVs, 3 coupés, 4 muscle, 5 sports classics, 6 sports, 7 super, 8 motorcycles, 9 off-road, 10 industrial, 11 utility, 12 vans, 17 service, 18 emergency, 20 commercial. The server reads the class from data/classes.lua (vanilla vehicles); addon vehicles use default unless listed in models.

-- data/loot.lua
SLTrunk.Loot.modify = function(ctx, items)
local hour = tonumber(os.date('%H'))
if hour >= 22 or hour < 6 then items[#items + 1] = { item = 'black_money', amount = 1000 } end
end
-- any other resource, server side
exports.sl_trunk:AddLootModifier(function(ctx, items)
if ctx.table == 'work' then return false end -- nothing
end)

A modifier can change items in place, return a new list, or return false for nothing. modify runs first, then the exports in the order they were added. Errors are printed and do not stop the loot.