# Creating New Document

This section will show you step-by-step how to properly register a new document.

Taking advantage of these steps will ensure that your document is prepared as expected.

***

## 1. Create your document theme

1. **Open PSD file:** Launch Adobe Photoshop and open the `id_card.psd` file, or if you don't have the aforementioned program, use the one you have and import an already finished file, such as `id_card.png` or use an already created document background, in which case go to [#id-2.-document-registration](#id-2.-document-registration "mention").
2. **Customize content:** You can change the colors or modify the entire layout.
3. **Save Changes:** After editing, save the document background in PNG format for use in the script.
4. **Upload PNG:** Upload your new .png file to vms\_documentsv2/html/images/

***

## 2. Document registration

To ensure the document is functional, you need to register it in `config.lua`. Let's create a weapon license document as an example. This license will contain information fields such as the individual's first name, last name, and height. To achieve this, open the `config.lua` file and locate `Config.Documents`. Then, create a new document object with the relevant details.

1. **Open config.lua**: This file holds configurations for documents and makes them useable.
2. **Create a New Document**: Inside `Config.Documents`, add a unique entry using the template provided. For example:

{% hint style="warning" %}
A**djust all parameters for the document and create an item in your inventory.**
{% endhint %}

<details>

<summary><strong>Create a New Document</strong></summary>

{% hint style="danger" %}
Remember not to set **itemName** as **`weapon_license`**, leave it as **`weapons_license`**, because some inventories block items with the prefix **`weapon_`** in order to identify weapons.
{% endhint %}

```lua
['weapon_license'] = {
    type = 'document', 
    itemName = 'weapons_license',
    identificationIdPrefix = 'WP-', 
    image = 'weapon_license.png', 
    animations = {
        view = {"cellphone@", "cellphone_text_read_base", -1, 51, 28422, {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}},
        show = {"random@atmrobberygen", "a_atm_mugging", 3000, 51, 28422, {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}},
    },
    prop = 'prop_franklin_dl',
    data = {
        'firstName',
        'lastName',
        'ssn',
        'height'
    },
    
    needAnyLicenseToGetDocument = true,
    licenses = {
        'weapon'
    },
}
```

* **`type`**: Specifies the document type (`'document'` or `'badge'`).
* **`itemName`**: Name of the item to inventory.
* **`identificationIdPrefix`**: A prefix for the document ID.
* **`image`**: Background image file for the document.
* **`animations`**: Defines the animations used for viewing or showing the document.
* **`prop`**: Prop that player will have in hand when using the item.
* **`data`**: Information fields displayed on the document (e.g., firstName, ssn, height).
* **`licenses`**: Licenses available for the document (e.g., drive\_a, weapon).

</details>

***

## 3. Introduction of new player data information

{% hint style="info" %}
`SV.getDocumentsData` obtains information from the `data` you have implemented in the section of the [#create-a-new-document](#create-a-new-document "mention") enter new parameters if any have been added.

As a reminder what the current `data` looks like from the added `weapon_license`:

```lua
data = {
    'firstName',
    'lastName',
    'ssn',
    'height'
},
```

For this document we need `firstName`, `lastName`, `ssn` and `height`.
{% endhint %}

1. **Open config.server.lua:** Find `SV.getDocumentsData` in your config.server.lua
2. **Find missing values:** For this you need to check what data is missing that we need from the `data`, we are looking for `firstName`, if there is `firstName`, we do not need to enter anything, the same with `lastName`, `ssn`, if there is no `height` for example, you should enter it.

<details>

<summary>Adding missing value to the <code>SV.getDocumentsData</code></summary>

```lua
['height'] = {
    dataName = 'height', -- is the name that will be used for SV.getPlayerData
    getData = function(self, src, xPlayer)
        local data = SV.getPlayerData(xPlayer, self.dataName)
        return data
    end
},
```

</details>

<figure><img src="/files/N6ptypqvXx9RVScPwRlR" alt=""><figcaption></figcaption></figure>

After entering the new information in `SV.getDocumentsData`, we need to enter it in `SV.getPlayerData` as well, since that's what the function references.

<details>

<summary>Adding missing function to the <code>SV.getPlayerData</code></summary>

```lua
SV.getPlayerData = function(xPlayer, name)
    if Config.Core == "ESX" then
        --if name == 'firstName' then
        --elseif name == 'lastName' then
        --elseif name == 'ssn' then            
        elseif name == 'height' then         -- ADDED
            return xPlayer.variables.height  -- ADDED
        end
    elseif Config.Core == "QB-Core" then
        --if name == 'firstName' then
        --elseif name == 'lastName' then
        --elseif name == 'ssn' then
        elseif name == 'height' then         -- ADDED
            return 0                         -- ADDED
        end
    end
end
```

</details>

<figure><img src="/files/84278aWtISRK2N5GIgKT" alt=""><figcaption></figcaption></figure>

***

## 4. Introduction of new player licenses information

{% hint style="info" %}
`SV.getDocumentsLicense` obtains information from the `licenses` you have implemented in the section [#create-a-new-document](#create-a-new-document "mention") enter new parameters if any have been added.

As a reminder of what the current `licenses` look like from the added `weapon_license`:

```lua
licenses = {
    'weapon'
},
```

For this document we need a `weapon`.
{% endhint %}

1. **Open config.server.lua:** Find `SV.getDocumentsLicense` in your config.server.lua
2. **Find missing values:** For this you need to check what licenses are missing, which we need from licenses, we are looking for `weapon`, if there is one, we do not need to enter anything, but if there is no `weapon` license, you need to enter it.

<details>

<summary>Adding missing license to the <code>SV.getDocumentsLicense</code></summary>

```lua
['weapon'] = {
    licenseName = 'weapon',
    getLicense = function(self, src, xPlayer, cb)
        SV.getLicense(src, xPlayer, self.licenseName, function(haveLicense)
            local text = 'No license'
            if haveLicense then
                text = 'License valid'
            end
            cb(text)
        end)
    end,
},
```

</details>

<figure><img src="/files/yndm7NQ8ulxTM7p8WsiR" alt=""><figcaption></figcaption></figure>

## 5. Customizing the displayed data

{% hint style="info" %}
**What is metadata.js and how to understand it?**

Metadata in vms\_documentsV2 is divided into 4 types: `data`, `data2`, `signature` and `document_name`.

* **`data`**: document content - information displayed.

```javascript
// Example:
returnVal.push({
    type: "data",
    label: "First Name:", // it's label, you can change it to your language
    value: data['firstName'] // insert the value with the document data here
})
```

* **`data2`**: badge second content next to photo

```javascript
// Example:
returnVal.push({
    type: "data2",
    label: "Badge number:",
    value: data['badgeNumber']
})
```

* **`signature`**: Handwrite font signature visible on the document.

```javascript
// Example:
returnVal.push({
    type: "signature",
    value: data['firstName'] + ' ' + data['lastName']
})
```

* **`document_name`**: Document name displayed at the top of the document.

```javascript
// Example:
returnVal.push({
    type: "document_name",
    value: "Weapon License"
})

```

{% endhint %}

1. **Open metadata.js**
2. **Register a new document:** You need to enter the data to be displayed on the document

<details>

<summary><strong>Register a new document</strong></summary>

```javascript
} else if (name == 'weapon_license') {
    returnVal.push({
        type: "data",
        label: "Owner:",
        value: data['firstName'] + ' ' + data['lastName']
    })
    
    returnVal.push({
        type: "data",
        label: "Height:",
        value: data['height'] // Added 'height' data
    })
    
    returnVal.push({
        type: "data",
        label: "Valid:",
        value: data['weapon'] // Added 'weapon' license
    })
    
    returnVal.push({
        type: "data",
        label: "Serial Number:",
        value: data['document_id'] // The serial number will always be assigned to the document
    })
    
    returnVal.push({
        type: "signature",
        value: data['firstName'] + ' ' + data['lastName']
    })
    
    returnVal.push({
        type: "document_name",
        value: "Weapon License"
    })
}
```

</details>

<figure><img src="/files/f9ldPC1N8Dqai876Oeul" alt=""><figcaption></figcaption></figure>

## 6. Result

<figure><img src="/files/8vz5ugeN4TZjMHlczLRe" alt=""><figcaption></figcaption></figure>


---

# 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://docs.vames-store.com/assets/vms_documentsv2/guides/creating-new-document.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.
