> ## Documentation Index
> Fetch the complete documentation index at: https://zyra-store.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Advanced usage

Zyra Store scripts are built with interoperability in mind. You can connect them with virtually any other resource on your server using FiveM's native **exports**, **events**, and **callbacks** system. In this guide you will learn how to make the most of these tools to create a completely customized experience.

***

## Client exports

**Exports** in Lua allow a resource to expose functions that other resources can call directly, without needing events. It is the simplest and most direct way to reuse logic between scripts.

The three available client exports are `GetPlayerData()`, `OpenMenu()`, and `TriggerCallback()`. Below is how to call them from another resource:

```lua other-resource/client.lua theme={null}
-- Get player data from the Zyra script
local playerData = exports['zyra-mi-script']:GetPlayerData()
print('Player:', playerData.name, '| Identifier:', playerData.identifier)

-- Open the script's main menu
exports['zyra-mi-script']:OpenMenu('main')

-- Trigger a callback to the server and receive the response on the client
exports['zyra-mi-script']:TriggerCallback('zyra-mi-script:getPlayerBalance', function(balance)
    print('Player balance:', balance)
end)
```

> [!WARNING]
>
> Replace `zyra-mi-script` with the exact resource name as it appears in its folder and in your `server.cfg`. An incorrect name will cause a runtime error.

See all available exports in the [client exports reference](https://zyra-store.mintlify.site/en/reference/exports/client-exports.md).

***

## Server exports

The script also exposes exports on the server side so other resources can register players, read the active configuration, and update player data in real time.

```lua other-resource/server.lua theme={null}
-- Register a player in the Zyra system when they connect
exports['zyra-mi-script']:RegisterPlayer(source)

-- Get the script's active configuration
local config = exports['zyra-mi-script']:GetConfig()
print('Active framework:', config.framework)

-- Update player data
exports['zyra-mi-script']:SetPlayerData(source, { coins = 500 })
```

***

## Listening to client events

Zyra Store scripts emit events at key moments in the resource lifecycle and player actions. You can listen to these events from any other resource to react to them.

```lua other-resource/client.lua theme={null}
-- React when the script is ready
AddEventHandler('zyra:onScriptReady', function()
    print('[MyResource] Zyra script ready, initializing integration...')
end)

-- React to a player action
AddEventHandler('zyra:onPlayerAction', function(action, data)
    if action == 'purchase' then
        TriggerEvent('my-resource:onPurchase', data)
    end
end)

-- React when the Zyra resource starts on the client
AddEventHandler('zyra:onResourceStart', function()
    print('[MyResource] Zyra resource started on the client.')
end)
```

See the complete list of available events in the [client events reference](https://zyra-store.mintlify.site/en/reference/events/client-events.md).

***

## Listening to server events

The server side emits its own events that you can capture to synchronize logic between resources or log administrative activity.

```lua other-resource/server.lua theme={null}
-- Player connected and registered by Zyra
AddEventHandler('zyra:onPlayerConnect', function(source, playerData)
    print('[MyResource] Player connected:', playerData.name)
end)

-- Administrator action executed
AddEventHandler('zyra:onAdminAction', function(source, action, target)
    print('[MyResource] Admin', source, 'executed:', action, 'on', target)
end)

-- Data synchronization between server and clients
AddEventHandler('zyra:onDataSync', function(source, syncData)
    -- React to player data synchronization
end)
```

***

## Custom callbacks

Callbacks allow you to send a request to the server and receive a response back on the client asynchronously. Zyra Store scripts are compatible with both **ESX** and **QBCore**.

> [tab] ESX
>
> ```lua other-resource/client.lua theme={null}
> -- Callback with ESX
> ESX.TriggerServerCallback('zyra-mi-script:getPlayerBalance', function(balance)
>     print('Player balance:', balance)
> end)
> ```
>
> ```lua other-resource/server.lua theme={null}
> -- Register the callback on the server (ESX)
> ESX.RegisterServerCallback('zyra-mi-script:getPlayerBalance', function(source, cb)
>     local xPlayer = ESX.GetPlayerFromId(source)
>     cb(xPlayer.getMoney())
> end)
> ```

> [tab] QBCore
>
> ```lua other-resource/client.lua theme={null}
> -- Callback with QBCore
> QBCore.Functions.TriggerCallback('zyra-mi-script:getPlayerBalance', function(balance)
>     print('Player balance:', balance)
> end)
> ```
>
> ```lua other-resource/server.lua theme={null}
> -- Register the callback on the server (QBCore)
> QBCore.Functions.CreateCallback('zyra-mi-script:getPlayerBalance', function(source, cb)
>     local Player = QBCore.Functions.GetPlayer(source)
>     cb(Player.PlayerData.money['cash'])
> end)
> ```

***

## Integration with Discord Logs

Zyra Store scripts include an integrated Discord logging system. To activate it, configure the following options in your `shared/config.lua`:

```lua shared/config.lua theme={null}
Config.Features = {
    discord_logs = true,
}

Config.Discord = {
    webhook = 'https://discord.com/api/webhooks/YOUR_WEBHOOK_HERE',
    botName = 'Zyra Logs',
    botAvatar = 'https://i.imgur.com/your-avatar.png',
    color = 3066993, -- Green (decimal)
}
```

Once enabled, each relevant player action will generate an embed in your Discord channel with the following format:

```text theme={null}
🟢 Zyra Store Logs
────────────────────
👤 Player  : PlayerName (ID: 1)
🔑 Identifier : license:abc123
⚙️  Action   : purchase
📦 Detail  : Item purchased: water x2
🕐 Date    : 01/01/2025 20:30:00
```

***

## Using ox\_lib with the scripts

When `Config.UseOxLib = true`, Zyra Store scripts use **ox\_lib** components for menus, inputs, and alerts, offering a modern and consistent interface.

Below is how to register and display a context menu with ox\_lib:

```lua client/main.lua theme={null}
lib.registerContext({
    id = 'zyra_main_menu',
    title = 'Zyra Menu',
    options = {
        { title = 'Option 1', description = 'Option description', onSelect = function() end },
        { title = 'Option 2', description = 'Option description', onSelect = function() end },
    }
})
lib.showContext('zyra_main_menu')
```

You can also use `lib.inputDialog` to request data from the player and `lib.alertDialog` for confirmations before executing critical actions.

> [!NOTE]
>
> Verify version compatibility before updating ox\_lib. Check the `dependencies` field in the `fxmanifest.lua` file of the Zyra Store resource to know the minimum required version of ox\_lib. Using an incompatible version may cause unexpected errors in menus and inputs.

***

For a complete reference of all available events and exports, see:

> [card] [Client events](https://zyra-store.mintlify.site/en/reference/events/client-events.md)
>
> Complete list of events the script emits on the client side.

> [card] [Client exports](https://zyra-store.mintlify.site/en/reference/exports/client-exports.md)
>
> All exported functions you can call from other resources.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.