> ## 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.

# Client events

**Client events** are messages that Zyra Store scripts emit in the client environment (the game running on the player's machine). You can listen to them from any other FiveM resource to react to what happens inside the script, such as when the player loads their data, opens a menu, or performs a tracked action.

To subscribe to any Zyra Store client event, use FiveM's native `AddEventHandler` function from a **client-side** file in your resource. The event name always follows the pattern `zyra:eventName`.

```lua other-resource/client.lua theme={null}
-- Listen to a Zyra Store client event
AddEventHandler('zyra:onScriptReady', function()
    print('The Zyra script is ready.')
end)
```

> [!WARNING]
>
> These events **can only be listened to from client scripts**. Attempting to register an `AddEventHandler` for these events in a server file will have no effect and may generate unexpected behavior in your resource.

***

## Event reference

> [accordion] zyra:onScriptReady
>
> Fires when the Zyra Store script has completed its initialization fully and is ready to operate. Use it to defer any logic that depends on the script being active.
>
> **Parameters**
>
> This event receives no parameters.
>
> **Example**
>
> ```lua other-resource/client.lua theme={null}
> AddEventHandler('zyra:onScriptReady', function()
>     -- The script is ready: you can initialize integrations here
>     print('[MyResource] Zyra Store is fully loaded.')
> end)
> ```

> [accordion] zyra:onPlayerReady
>
> Fires when the local player's data has been correctly loaded by the script. From this moment on you can assume that the player information is available.
>
> **Parameters**
>
> **identifier** `string` *required*
>
> The player's license identifier (for example, `license:a1b2c3d4...`). Used to reference the player uniquely within the script.
>
> **Example**
>
> ```lua other-resource/client.lua theme={null}
> AddEventHandler('zyra:onPlayerReady', function(identifier)
>     print(('[MyResource] Player ready with identifier: %s'):format(identifier))
>     -- For example, load additional data from your own resource
> end)
> ```

> [accordion] zyra:onPlayerAction
>
> Fires every time the player performs an action that the script tracks internally. You can use this event to react to specific actions in real time.
>
> **Parameters**
>
> **action** `string` *required*
>
> The name of the performed action, for example `"purchase"`, `"interact"`, or `"use_item"`.
>
> **data** `table` *required*
>
> A table with information specific to the action. The content varies depending on the `action` value.
>
> **Common data structure**
>
> **timestamp** `number`
>
> Unix timestamp of the moment the action occurred.
>
> **metadata** `table`
>
> Additional optional data that the script attaches depending on the action type.
>
> **Example**
>
> ```lua other-resource/client.lua theme={null}
> AddEventHandler('zyra:onPlayerAction', function(action, data)
>     if action == 'purchase' then
>         print(('[MyResource] The player made a purchase.'))
>         -- Access the specific action data
>         if data and data.metadata then
>             print(('Metadata: %s'):format(json.encode(data.metadata)))
>         end
>     elseif action == 'interact' then
>         print('[MyResource] The player interacted with an object.')
>     end
> end)
> ```

> [accordion] zyra:onMenuOpen
>
> Fires when the player opens the script's main menu. You can use this event to pause your resource's logic while the menu is active.
>
> **Parameters**
>
> **menuId** `string` *required*
>
> The unique identifier of the menu that was opened (for example, `"main"`, `"shop"`, `"settings"`).
>
> **Example**
>
> ```lua other-resource/client.lua theme={null}
> AddEventHandler('zyra:onMenuOpen', function(menuId)
>     print(('[MyResource] Menu opened: %s'):format(menuId))
>     -- For example, disable your resource's keys while the menu is open
>     if menuId == 'main' then
>         DisableControls(true)
>     end
> end)
> ```

> [accordion] zyra:onMenuClose
>
> Fires when any script menu is closed by the player. Use it to restore your resource's state when exiting the menu.
>
> **Parameters**
>
> **menuId** `string` *required*
>
> The unique identifier of the menu that was closed. Matches the `menuId` received in `zyra:onMenuOpen`.
>
> **Example**
>
> ```lua other-resource/client.lua theme={null}
> AddEventHandler('zyra:onMenuClose', function(menuId)
>     print(('[MyResource] Menu closed: %s'):format(menuId))
>     -- Restore controls or other resource state
>     if menuId == 'main' then
>         DisableControls(false)
>     end
> end)
> ```

> [accordion] zyra:onNotification
>
> Fires just before the script shows a notification to the player. You can intercept this event to replace the script's notification system with your own resource's.
>
> **Parameters**
>
> **type** `string` *required*
>
> The notification type. Possible values are:
>
> * `"success"` — operation completed successfully
> * `"error"` — an error occurred
> * `"warning"` — warning to the player
> * `"info"` — general informational message
>
> **message** `string` *required*
>
> The message text that would be shown to the player.
>
> **Example**
>
> ```lua other-resource/client.lua theme={null}
> AddEventHandler('zyra:onNotification', function(type, message)
>     -- Use your resource's notification system instead of the default one
>     if type == 'success' then
>         TriggerEvent('mySystem:notify', message, 'green')
>     elseif type == 'error' then
>         TriggerEvent('mySystem:notify', message, 'red')
>     elseif type == 'warning' then
>         TriggerEvent('mySystem:notify', message, 'orange')
>     else
>         TriggerEvent('mySystem:notify', message, 'blue')
>     end
> end)
> ```

***

## Best practices

When working with Zyra Store client events, keep the following recommendations in mind:

**Do not modify received data directly.** The parameters you receive in callbacks are references to the script's internal data. Only modify local copies if you need to transform the information.

```lua other-resource/client.lua theme={null}
AddEventHandler('zyra:onPlayerAction', function(action, data)
    -- ✅ Correct: work with a local copy
    local localData = data
    localData.processed = true

    -- ❌ Incorrect: do not try to modify the script's original table
end)
```

**Clean up your event handlers when you no longer need them.** If your resource registers listeners dynamically, use `RemoveEventHandler` to avoid memory leaks and unexpected behavior.

```lua other-resource/client.lua theme={null}
-- Save the handler reference
local handler = AddEventHandler('zyra:onMenuOpen', function(menuId)
    print('Menu opened: ' .. menuId)
end)

-- When you no longer need it, remove it
RemoveEventHandler(handler)
```

**Register your listeners after `zyra:onScriptReady`.** To guarantee that the script is active before your logic depends on it, subscribe to other events within the `zyra:onScriptReady` callback.

***

## Related resources

* See the [Server Events](https://zyra-store.mintlify.site/en/reference/events/server-events.md) for the server-side counterpart of these events.


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