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

# Log event

The vision\_badges:log server event - every issue, revocation and Studio change.

Issues, revocations and Studio changes fire the **server** event `vision_badges:log` with an action name and a data table. Listen to it to feed your own log system (Discord, database...).

```lua
AddEventHandler('vision_badges:log', function(action, data)
    -- action: see the table below
end)
```

{% hint style="warning" %}
It's a **local** server event (`TriggerEvent`), so players can't fire it. Listen with **`AddEventHandler`**, never `RegisterNetEvent`, which would let clients fake it.
{% endhint %}

## Actions

| Action            | When                                                                      | Data fields                                                           |
| ----------------- | ------------------------------------------------------------------------- | --------------------------------------------------------------------- |
| `badge_issued`    | A badge was issued                                                        | `serial`, `type`, `number`, `name`, `citizenid`, `issuer`, `issuerId` |
| `badge_revoked`   | One badge was revoked (Registry **Revoke**, `RevokeBadge` export)         | `serial`, `by`                                                        |
| `person_revoked`  | Registry **Revoke all of this person**, `RevokeCitizenBadges` export      | `citizenid`, `type` (`nil` = every type), `count`, `by`               |
| `badges_replaced` | A new badge voided the person's older badges of the same type             | `citizenid`, `type`, `keep`, `count`, `by`                            |
| `badge_saved`     | A badge type was created or saved in the Studio                           | `id`, `by`                                                            |
| `badge_deleted`   | A Studio badge was deleted, or an edited file badge was reset to the file | `id`, `by`                                                            |
| `desk_saved`      | A desk was created or saved in the Studio                                 | `id`, `by`                                                            |
| `desk_deleted`    | A Studio desk was deleted, or an edited file desk was reset to the file   | `id`, `by`                                                            |

## Fields

| Field                | Content                                                                                                                      |
| -------------------- | ---------------------------------------------------------------------------------------------------------------------------- |
| `serial`             | Badge serial (integer)                                                                                                       |
| `type`               | Badge id                                                                                                                     |
| `number`             | Badge number text (`LSPD-1001`)                                                                                              |
| `name`, `citizenid`  | Recipient's name and identifier                                                                                              |
| `issuer`, `issuerId` | Issuer's name and identifier                                                                                                 |
| `count`              | Number of badges revoked                                                                                                     |
| `id`                 | Badge or desk id                                                                                                             |
| `keep`               | Serial of the new badge that replaced the older ones                                                                         |
| `by`                 | Studio actions: the admin's FiveM name. Exports: their `by` argument, or the calling resource. Re-issues: the issuer's name. |

## Examples

{% tabs %}
{% tab title="Console log" %}

```lua
-- server script in your own resource
AddEventHandler('vision_badges:log', function(action, data)
    if action == 'badge_issued' then
        print(('[badges] %s issued %s badge %s (#%06d) to %s [%s]'):format(
            data.issuer, data.type, data.number, data.serial, data.name, data.citizenid))
    elseif action == 'badge_revoked' then
        print(('[badges] badge #%06d revoked by %s'):format(data.serial, data.by))
    elseif action == 'person_revoked' then
        print(('[badges] %d badge(s) of %s revoked by %s'):format(data.count, data.citizenid, data.by))
    elseif action == 'badges_replaced' then
        print(('[badges] %d older %s badge(s) of %s replaced by #%06d'):format(
            data.count, data.type, data.citizenid, data.keep))
    else
        print(('[badges] %s "%s" by %s'):format(action, data.id, data.by))
    end
end)
```

{% endtab %}

{% tab title="Discord webhook" %}

```lua
local WEBHOOK = 'https://discord.com/api/webhooks/...'

AddEventHandler('vision_badges:log', function(action, data)
    local text
    if action == 'badge_issued' then
        text = ('🪪 **%s** issued %s badge **%s** to **%s**'):format(data.issuer, data.type, data.number, data.name)
    elseif action == 'badge_revoked' then
        text = ('⛔ Badge #%06d revoked by %s'):format(data.serial, data.by)
    elseif action == 'person_revoked' then
        text = ('⛔ %d badge(s) of %s revoked by %s'):format(data.count, data.citizenid, data.by)
    end
    if not text then return end
    PerformHttpRequest(WEBHOOK, function() end, 'POST', json.encode({ content = text }),
        { ['Content-Type'] = 'application/json' })
end)
```

{% endtab %}
{% endtabs %}

The server console prints issues, revocations and Studio changes as well.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://visionstore.gitbook.io/visionstore-docs/scripts/badges/developers/log-event.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
