> For the complete documentation index, see [llms.txt](https://k0ssek-scripts.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://k0ssek-scripts.gitbook.io/docs/scripts/easter-event/framework-bridge.md).

# Framework Bridge

Framework and inventory support, and how to adapt it.

Everything that depends on your framework or your inventory is in the `bridge/` folder. The folder is not encrypted, so you can adapt it to your server.

```
bridge/
  init.lua
  framework/
    esx/client.lua      esx/server.lua
    qbcore/client.lua   qbcore/server.lua
    qbx/client.lua      qbx/server.lua
  inventory/
    server.lua
```

## Frameworks

The framework is detected when the resource starts. There is nothing to set.

| Framework  | Detected by   | Player identifier | Notifications       |
| ---------- | ------------- | ----------------- | ------------------- |
| ESX Legacy | `es_extended` | ESX identifier    | ESX notification    |
| QBCore     | `qb-core`     | Citizen ID        | QBCore notification |
| QBX        | `qbx_core`    | Citizen ID        | QBX notification    |

The framework has to be started before kossek\_easter. There is no standalone mode.

### Admin check

| Framework | A player is an admin when                                           |
| --------- | ------------------------------------------------------------------- |
| ESX       | Their group is listed in `Config.AdminGroups` (`config/server.lua`) |
| QBCore    | They have the QBCore `admin` permission or the `command` ace        |
| QBX       | They have the `qbx_core.admin` ace or the `command` ace             |

To use your own rule, edit `Bridge.Framework.IsAdmin` in the server file of your framework.

## Inventories

Items are given and taken through the framework, or through ox\_inventory when it is running. On QBX, ox\_inventory is required.

Incubation works in one of two ways, depending on the inventory:

| Inventory                                                         | Incubation                                                                                      |
| ----------------------------------------------------------------- | ----------------------------------------------------------------------------------------------- |
| ox\_inventory                                                     | Per egg. The progress is stored in the item data and shown on the item.                         |
| qs-inventory                                                      | Per egg. The progress is stored in the item data.                                               |
| qb-inventory                                                      | Per egg. The progress is stored in the item data.                                               |
| ak47\_inventory, ak47\_qb\_inventory                              | Per egg. The progress is stored in the item data.                                               |
| Any other (ps-inventory, lj-inventory, the default ESX inventory) | One egg at a time. The progress is stored in the `easter_stats` table and survives a reconnect. |

The first inventory from this list that is running is used. The server console prints the result on start, for example `ox_inventory detected — using per-item metadata for incubation.` or `No metadata-capable inventory found — using fallback single-egg incubation.`

### Free space check on QBCore

Before the script gives an item, it checks that the player has room for it. On QBCore the check uses ox\_inventory or ak47\_qb\_inventory when one of them is running, and the weight export of qb-inventory (`GetTotalWeight`) otherwise.

ps-inventory and lj-inventory do not always provide that export under the `qb-inventory` name. When it is missing, the weight check is skipped and the inventory itself decides whether the item fits at the moment it is added. If it refuses the item, the player keeps the egg or the eggshells and is told that there is no space, the same as with any other inventory.

To check the space your own way, edit `Bridge.Framework.CanCarryItem` in `bridge/framework/qbcore/server.lua`.

### Item images

The image folder is detected for ox\_inventory, qb-inventory, qs-inventory, ps-inventory, lj-inventory and ak47. For another inventory set `Config.ItemImagePath` yourself, see [Configuration](/docs/scripts/easter-event/configuration.md).

## Functions you can change

The game logic only talks to the functions below. Keep the names, the parameters and the return values, and change what happens inside.

### Server: Bridge.Framework

| Function                                  | Returns       | Purpose                                                                                                                           |
| ----------------------------------------- | ------------- | --------------------------------------------------------------------------------------------------------------------------------- |
| `GetPlayerIdentifier(source)`             | string or nil | Identifier used as the key in `easter_stats`                                                                                      |
| `GetPlayerCharacterName(source)`          | string or nil | Character name for the scoreboard                                                                                                 |
| `GetItemCount(source, itemName)`          | number        | How many of an item the player has                                                                                                |
| `GetItemLabel(itemName)`                  | string        | Display name of an item                                                                                                           |
| `AddItem(source, itemName, count)`        | boolean       | Give an item. Has to return `false` when the item was not added: the script then leaves the egg or the eggshells with the player. |
| `RemoveItem(source, itemName, count)`     | boolean       | Take an item                                                                                                                      |
| `CanCarryItem(source, itemName, count)`   | boolean       | Whether the player has room for the item                                                                                          |
| `RegisterUsableItem(itemName, callback)`  |               | Makes the egg items usable                                                                                                        |
| `Notify(source, notifyType, description)` |               | Sends a notification to a player                                                                                                  |
| `IsAdmin(source)`                         | boolean       | Access to the admin panel and commands                                                                                            |
| `OnPlayerLoaded(callback)`                |               | Runs the callback when a player's character is loaded                                                                             |
| `OnPlayerDropped(callback)`               |               | Runs the callback when a player leaves                                                                                            |

### Server: Bridge.Inventory

Used only for per-egg incubation.

| Function                                                    | Returns      | Purpose                                                    |
| ----------------------------------------------------------- | ------------ | ---------------------------------------------------------- |
| `SupportsMetadata`                                          | boolean      | A value, not a function. `false` selects the one-egg mode. |
| `GetItemSlots(source, itemName)`                            | table or nil | List of slots with that item: `slot`, `count`, `metadata`  |
| `SetSlotMetadata(source, slot, metadata)`                   |              | Writes the item data of one slot                           |
| `RemoveItemWithMetadata(source, itemName, count, metadata)` | boolean      | Removes an item whose data matches the given fields        |

To add per-egg incubation for another inventory, add a branch for it in `bridge/inventory/server.lua` with these three functions and `SupportsMetadata = true`.

### Client: Bridge.Framework

| Function                          | Returns | Purpose                             |
| --------------------------------- | ------- | ----------------------------------- |
| `IsPlayerLoaded()`                | boolean | Whether the character is loaded     |
| `WaitForPlayerLoaded()`           |         | Waits until the character is loaded |
| `Notify(notifyType, description)` |         | Shows a notification                |

`notifyType` is `success`, `error` or `info`.

### Example: ox\_lib notifications

To show the notifications of the script with ox\_lib, replace the body of `Bridge.Framework.Notify` in the **client** file of your framework:

```lua
function Bridge.Framework.Notify(notifyType, description)
    lib.notify({ type = notifyType, description = description })
end
```

Notifications sent by the server go through the same function, so this one change covers both.

## Updating

An update replaces the `bridge/` folder. Keep a copy of the files you changed and apply your changes again after updating.
