# Exports & Events

This script allows registering and opening dynamic shops on your FiveM server using simple exports and events.

***

### Export: `exports.lvs_shops:RegisterShop`

#### Syntax (server-side)

```lua
exports.lvs_shops:RegisterShop(shopId, shopData)
```

#### Parameters

* **shopId** (*string*): A unique identifier for the shop.
* **shopData** (*table*): A table containing the shop's settings and inventory.

**shopData Structure**

* **name** (*string*): Display name of the shop.
* **inventory** (*table*): A list of items available in the shop. Each item should be a table with:
  * `name` (*string*): Item name.
  * `price` (*number*): Item price.
  * `type` (*string, optional*): Item type (for categorization or filtering).
* **groups** (*table*): Restriction list based on player groups (e.g., `police = 0` for group access).
* **description** (*string*, optional): A short description of the shop.
* **filters** (*table*, optional): Used to organize shop items by categories. Each filter is a table with:
  * `type` (*string*): The item type this filter applies to.
  * `label` (*string*): Display label for the filter.
  * `description` (*string*): Additional description for the filter.
  * `icon` (*string*): Icon for the filter (currently not implemented).

#### Example Usage

```lua
exports.lvs_shops:RegisterShop('TestShop', {
    name = 'Test shop',
    inventory = {
        { name = 'burger', price = 10, type = 'drink' },
        { name = 'water', price = 10, type = 'drink' },
        { name = 'cola', price = 10, type = 'drink' },
    },
    groups = {
        police = 0
    },
    description = 'Some description bla bla',
    filters = {
        {
            type = 'drink',
            label = 'Drinks',
            description = 'Something refreshing',
        }
    },
})
```

***

### Event: `lvs_shops:client:openRuntimeShop`

#### Syntax (client-side)

```lua
TriggerEvent('lvs_shops:client:openRuntimeShop', shopId)
```

#### Parameters

* **shopId** (*string*): The ID of the shop you registered previously.

#### Description

This client-side event opens the specified runtime shop UI for the player.

#### Example Usage

```lua
TriggerEvent('lvs_shops:client:openRuntimeShop', 'TestShop')
```

***

### Notes

* `shopId` **must** be unique when registering a new shop to avoid conflicts.
* You can expand the `shopData` with more optional fields like in `shops.lua` of `lvs_shops` if needed.
* Group restrictions (`groups`) allow you to make certain shops accessible only to specific player groups or jobs.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://fivem.lvsoft.com.ar/qb-esx/lvs-shops/exports-and-events.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
