> For the complete documentation index, see [llms.txt](https://code-after-sex.gitbook.io/script-documentation/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://code-after-sex.gitbook.io/script-documentation/vip-shop/configuration/memberships.md).

# Memberships & Discounts

Tier definitions live in `Config.Memberships`:

```lua
Config.Memberships = {
    marshal = {
        label = 'Marshal', discount = 0.10, order = 2,
        rewards = {
            { type = 'coins',  amount = 1200 },
            { type = 'cash',   amount = 750 },
            { type = 'gold',   amount = 5 },
            { type = 'item',   vorp = 'bandage', rsg = 'bandage', count = 3 },
            { type = 'ammo',   vorp = 'AMMO_REPEATER_NORMAL', rsg = 'ammo_repeater', count = 200 },
            { type = 'weapon', weapon = 'WEAPON_REVOLVER_SCHOFIELD' },
        },
    },
    -- deputy, legend and founder follow the same shape
}
```

| Field               | Meaning                                                                                                                                                                                    |
| ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| key (`deputy`, ...) | The tier id used in commands and the database                                                                                                                                              |
| `label`             | Display name shown to players and in logs                                                                                                                                                  |
| `discount`          | Fraction taken off every coin purchase (`0.10` means 10%)                                                                                                                                  |
| `lifetime`          | Cosmetic flag, shown as lifetime instead of a renewal date                                                                                                                                 |
| `rewards`           | The bundle `vipshop_givetier` delivers on purchase and every renewal. Accepts every catalog delivery type: `coins`, `cash`, `gold`, `item`, `ammo`, `weapon`, `horse`, `command`, `event`. |

You can add, rename or re-rate tiers freely; the commands validate against this table.

## The reward bundle

`vipshop_givetier <serverId> <tier>` runs the tier's `rewards` list through the same delivery engine as catalog purchases: items respect the dual `vorp`/`rsg` names, horses are written straight to the stable database, and `coins` credit the wallet with a live balance update. The target must be online, so keep "Require player to be online" enabled on the Tebex package.

## How the discount is applied

On every coin purchase the server computes:

```
total = floor(price x quantity x (1 - discount) + 0.5)
```

The UI mirrors the same formula, so the player sees the exact discounted total, the struck through original, and a tier chip before confirming. Because the calculation is repeated server side, a modified client cannot change what is charged.

## Storage and expiry

Memberships are one row per wallet in `vipshop_memberships`:

* `tier` holds the current tier id.
* `expires_at` is `NULL` for lifetime, otherwise a datetime. Expired rows are treated, and cleaned up, as no membership on the next read.

Tebex renewals refresh the expiry (`... marshal 35` means 35 days from now). A Tebex expiry or cancellation fires `... none`, which deletes the row immediately. The day counter is a grace window safety net, not the primary mechanism.

## Granting manually

```
vipshop_setmembership <serverId|identifier> <tier|none> [days]
```

* Console or the `vipshop.admin` ace.
* Online targets get a notification and, if the shop is open, the Passes page updates live.
* Omit `[days]` for a lifetime grant.

## Reading from other resources

```lua
local tier = exports.vip_shop:GetMembershipTier(source)  -- 'marshal' | nil
```

Useful for priority queues, chat colors, or any perk you want to key off VIP status.
