-- Example: Create a loot crate with dynamic loot based on rarity
-- Don't forget to secure the event somehow depending on your use case, otherwise cheaters can simply trigger the event to get free loot
RegisterNetEvent('myresource:openLootCrate', function(rarity)
local playerId = source
-- Define loot pools based on rarity
local lootPools = {
common = {
minTypes = 1,
maxTypes = 2,
items = {
{ name = "water", chance = 15, min = 1, max = 3 },
{ name = "bread", chance = 15, min = 1, max = 2 },
{ name = "bandage", chance = 10, min = 1, max = 2 },
}
},
rare = {
minTypes = 2,
maxTypes = 4,
items = {
{ name = "water", chance = 10, min = 2, max = 4 },
{ name = "bread", chance = 8, min = 2, max = 3 },
{ name = "bandage", chance = 8, min = 2, max = 3 },
{ name = "lockpick", chance = 5, min = 1, max = 2 },
{ name = "weapon_pistol", chance = 2, min = 1, max = 1 },
}
},
legendary = {
minTypes = 3,
maxTypes = 5,
items = {
{ name = "water", chance = 8, min = 3, max = 5 },
{ name = "bandage", chance = 8, min = 3, max = 4 },
{ name = "lockpick", chance = 6, min = 2, max = 3 },
{ name = "weapon_pistol", chance = 4, min = 1, max = 1 },
{ name = "weapon_rifle", chance = 2, min = 1, max = 1 },
}
}
}
local selectedLoot = lootPools[rarity] or lootPools.common
local inventory = exports['jaksam_inventory']:createInventory(
nil, -- Auto generate ID
"Loot Crate (" .. rarity .. ")", -- Dynamic label
{
temporary = true, -- Inventory will be lost on script restart
maxSlots = 5,
maxWeight = 50.0,
disableIncoming = true, -- Items cannot be added to this inventory by the player
prefillItems = selectedLoot,
revealItems = {
delayPerItem = 1000,
randomOrder = true
}
},
nil,
'stash',
nil
)
-- Open the inventory interface for the player
if inventory then
exports['jaksam_inventory']:forceOpenInventory(playerId, inventory.id)
end
end)