> For the complete documentation index, see [llms.txt](https://dynyx-scripts.gitbook.io/dynyx-scripts/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://dynyx-scripts.gitbook.io/dynyx-scripts/cards/exports-and-usage.md). Agents can also search and read this documentation through its [MCP server](https://dynyx-scripts.gitbook.io/dynyx-scripts/~gitbook/mcp).

# Exports & Usage

## 🖥️ Server Exports

### 💳 GiveCard

Grants a card to a player. Auto-picks the default ID card type when none is specified, and issues with no photo by default (the photo auto-captures the first time the player uses the card).

```lua
exports['dynyx_cards']:GiveCard(src, typeKey, opts)
```

#### Parameters

* **src** *(number)* Player server ID.
* **typeKey** *(string | nil)* The card's `type_key`. Pass `nil` to auto-pick the first non-badge card type registered in Cards Admin.
* **opts** *(table | nil)* Optional overrides:
  * **photo** *(string | nil)* Base64 data URL. Leave `nil` to let the first-use backfill capture it.
  * **data** *(table | nil)* Extra fields merged into the card data before insert.
  * **issuedBy** *(string)* Audit log label. Defaults to `"Export"`.
  * **isFake** *(boolean)* Flags the card as forged.
  * **enforceRequirements** *(boolean)* When `true`, runs the matching `Config.IssueRequirements` predicate before issuing. Still respects the per-card "Follow Issue Requirements" admin toggle. Defaults to `false` so trusted internal callers keep working without a code change.

#### Returns

* **ok** *(boolean)* `true` on success.
* **result** *(string)* Document number on success, short reason on failure (also printed to the server console when `Config.Debug` is on).

#### Example 1 : hand out a starter ID and Driver's License on new character

Hook into whichever event your multicharacter resource fires when a fresh character is created and call `GiveCard` once per document. Each card lands in the player's inventory and snaps a photo the first time they open it.

```lua
RegisterNetEvent('your_multicharacter:server:newCharacter', function()
    local src = source

    exports['dynyx_cards']:GiveCard(src, 'id_card', {
        issuedBy = 'Character Creation',
    })

    exports['dynyx_cards']:GiveCard(src, 'drivers_license', {
        issuedBy = 'Character Creation',
    })
end)
```

Swap `'your_multicharacter:server:newCharacter'` for the event name your multicharacter resource fires. Common ones look like `qb-multicharacter:server:createCharacter`, `qbx_core:server:characterCreated`, or `esx_multicharacter:onCharacterChange`, depending on your setup.

#### Example 2: gate behind requirements at issue time

Useful when a trusted script (driving school after a passed test, gun range, lawyer's office) wants the same metadata / job / item check that a public NPC location would apply:

```lua
local ok, result = exports['dynyx_cards']:GiveCard(src, 'firearms_license', {
    issuedBy            = 'Shooting Range',
    enforceRequirements = true,
})

if not ok then
    -- result holds the denial message from the predicate
    TriggerClientEvent('ox_lib:notify', src, { type = 'error', description = result })
end
```

***

### 🛡️ MeetsIssueRequirement

Checks whether a player would pass the `Config.IssueRequirements` predicate for a given card type — without issuing anything. Useful for letting other resources confirm a player has "earned" a license before opening a replacement / renewal flow, without poking at metadata directly. Server-side only.

```lua
exports['dynyx_cards']:MeetsIssueRequirement(src, typeKey)
```

#### Parameters

* **src** *(number)* Player server ID.
* **typeKey** *(string)* The card's `type_key` from Cards Admin.

#### Returns

* **allowed** *(boolean)* `true` if the player passes the predicate (or no predicate is defined / the per-card "Follow Issue Requirements" toggle is off).
* **message** *(string | nil)* Denial message returned by the predicate when `allowed` is `false`. `nil` on pass.

#### Example: only show "Replace License" when the player already has one

```lua
local function openLicenseMenu(src)
    local hasIt = exports['dynyx_cards']:MeetsIssueRequirement(src, 'drivers_license')

    lib.registerContext({
        id    = 'driving_school_menu',
        title = 'Driving School',
        options = {
            { title = 'Take the driving test', onSelect = startTest },
            hasIt and {
                title       = 'Replace Driver\'s License ($50)',
                description = 'Print a new card for your existing license.',
                onSelect    = function() replaceLicense(src) end,
            } or nil,
        },
    })
    lib.showContext('driving_school_menu')
end
```
