# Server event

Events you can listen to from your own resources. They are fired during the script's normal lifecycle (delivery, subscriptions, etc.).

### Delivery events

| Event                     | Arguments                            | Trigger                                      |
| ------------------------- | ------------------------------------ | -------------------------------------------- |
| `var-shop:deliver`        | `(src, identifier, items)`           | Fires on every delivery (framework-agnostic) |
| `var-shop:deliver:esx`    | `(src, identifier, items, xPlayer)`  | Fires when ESX is detected                   |
| `var-shop:deliver:qbcore` | `(src, identifier, items, qbPlayer)` | Fires when QBCore is detected                |

`items` is an array of:

```lua
{
  { id = "rebla", label = "Rebla GTS", kind = "vehicle", qty = 1, meta = { upgrades = { "perf" } } },
  { id = "WEAPON_AK4K", label = "AK-4K", kind = "weapon", qty = 1 },
}
```

### Subscription events

| Event                             | Arguments                                 | Trigger                           |
| --------------------------------- | ----------------------------------------- | --------------------------------- |
| `var-shop:subscription:activated` | `(source, identifier, plan, state, item)` | A subscription was just activated |
| `var-shop:subscription:expired`   | `(identifier, state)`                     | A subscription expired            |
| `var-shop:subscriptions:updated`  | `(plans)`                                 | Plans list updated at runtime     |

### Example : grant priority queue on VIP subscription

```lua
AddEventHandler("var-shop:subscription:activated", function(source, identifier, plan, state, item)
  if plan.id == "sub_vip" then
    exports['my-priority']:grantPriority(identifier, plan.durationDays)
  end
end)
```

### Example : log every delivery

```lua
AddEventHandler("var-shop:deliver", function(src, identifier, items)
  print(("[shop-log] %s received %d item(s)"):format(identifier, #items))
end)
```

### Custom delivery routing

If you want to route a specific item kind to your own event, configure it in `shared/config.lua`:

```lua
Delivery = {
  Handlers = {
    vehicle = { Event = "myserver:giveVehicle" },
  },
  FallbackEvent = "var-shop:deliver:item",
}
```

Your event handler receives `(src, identifier, item)`.

See Delivery customization for the full picture.


---

# 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://doc.var-fivem.com/coins-shop/configuration/server-event.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.
