Cases
Cases is a server side case tracking and opening system built into the bridge for creating case types that can be opened and their possible loots, it also includes all logic for handling cases being opened.
How it works
- You create a case type either by editing the
ALL_CASEStable or by using the exports provided below, with a unique ID and all items with their chances, min and max (you can also override an item image by using theimagefield). - A player is given a
caseitem with the metadata storingcaseIdas the cases unique ID. - When the player uses a case, the server with look for available items from the case and pick one based on random weighted math, all item handling is done server side for maximum security.
item chances
All items must add up to the total chance of 100, if they don't, that case will not be usable.
Installation
Add the case item to your inventory resource using the format appropriate for your setup.
Add items listed below to your ox_inventory into data/items.lua.
lua
["case"] = {
label = "Case",
weight = 1000
},Server Exports
CreateCase
Registers a new case type.
lua
exports["prp-bridge"]:CreateCase(caseId, payload)| Parameter | Type | Description |
|---|---|---|
caseId | string | Unique identifier for this case. |
payload | CaseDataPayload | Config (see below). |
Returns: boolean
trueon successfalseif the case item chances don't sum to 100
GetCase
Gets a case's data based on its unique identifier.
lua
exports["prp-bridge"]:GetCase(caseId)GetAllCases
Gets all cases currently created.
lua
exports["prp-bridge"]:GetAllCases()Returns: CaseDataPayload[] containing all registered case types and their items.
Payload
| Field | Type | Required | Description |
|---|---|---|---|
label | string | No | The label of the case type. |
items | CaseItem[] | Yes | All the possible items in a case. |
CaseItem
| Field | Type | Required | Description |
|---|---|---|---|
name | string | Yes | The name of the item in the case total items. |
image | string | No | An overridge image for the item in the case total items. |
metadata | string | No | Any custom metadata to apply to the item in the case total items. |
chance | number | Yes | The chance to get the item out of all the case total items. |
min | number | No | The minimum amount of said item you can get. |
max | number | No | The maximum amount of said item you can get. |
Examples
Simple test case example
lua
exports["prp-bridge"]:CreateCase("TEST_CASE", {
items = {
{
name = "money",
chance = 30,
min = 300,
max = 800,
},
{
name = "lockpick",
chance = 70
}
}
})