> For the complete documentation index, see [llms.txt](https://doc.var-fivem.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://doc.var-fivem.com/coins-shop/configuration/server-event.md).

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