RegisterNetEvent('myresource:openCase', function(caseName) local src = source -- Remove the item manually first exports.ox_inventory:RemoveItem(src, caseName, 1) -- Open with skipItemRemoval = true exports.sleepless_lootbox:open(src, caseName, true)end)
local items = exports.sleepless_lootbox:getPreview('gun_case')if items then for _, item in ipairs(items) do print(item.name, item.chance .. '%', item.rarity) endend
Register a custom reward handler for a specific reward type. This allows external resources to handle non-item rewards like vehicles, bank deposits, or any custom reward logic.
Reward was handled by the hook, skip default item logic
false or nil
Hook did not handle the reward, fall back to default item logic
If a reward has a rewardType set but no hook is registered for it, the system will log a warning and fall back to default item behavior to prevent reward loss.
-- Register a handler for 'vehicle' reward typesexports.sleepless_lootbox:registerRewardHook('vehicle', function(source, reward, caseName) local data = reward.rewardData -- data contains whatever you put in rewardData in your config -- e.g., { model = 'adder', garage = 'legion' } -- Example with qbx_vehicles local success = exports.qbx_vehicles:CreatePlayerVehicle({ source = source, model = data.model, garage = data.garage or 'legion', }) if success then -- Notify the player TriggerClientEvent('ox_lib:notify', source, { title = 'Vehicle Won!', description = 'Your ' .. reward.label .. ' has been added to your garage', type = 'success', }) return true -- We handled this reward end return false -- Something went wrong, fall back to default behaviorend)
-- Register a handler for 'bank' reward typesexports.sleepless_lootbox:registerRewardHook('bank', function(source, reward, caseName) local data = reward.rewardData -- data contains: { amount = 50000 } -- Example with QBCore local Player = exports.qbx_core:GetPlayer(source) if Player then Player.Functions.AddMoney('bank', data.amount, 'lootbox-reward') return true end return falseend)
-- Remove the vehicle hook (e.g., when your resource stops)exports.sleepless_lootbox:removeRewardHook('vehicle')
If you register hooks from another resource, consider removing them in that resource's onResourceStop handler to prevent errors if the resource restarts.