# 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="https://3701050178-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6y0J5nnTjSyc65fbCvIU%2Fuploads%2FSfblqKzqvBV5iWJXjEmj%2Fxczxczz-1.png?alt=media&#x26;token=16fe11e7-4615-4a57-972b-67af77a8de87" 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="https://3701050178-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6y0J5nnTjSyc65fbCvIU%2Fuploads%2FRwxwe91seRVf7WdqOeO5%2Fsdasdasdy-2.png?alt=media&#x26;token=29162027-f007-482f-93e0-d42efa677d7a" 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="https://3701050178-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6y0J5nnTjSyc65fbCvIU%2Fuploads%2FlqqKqrb45NGjD6DPtzoC%2Fdasdasdy-3.png?alt=media&#x26;token=8d93c2eb-9e4e-4656-aba8-5c88adfb9e93" 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="https://3701050178-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6y0J5nnTjSyc65fbCvIU%2Fuploads%2FqLQMvfkeUJsQkM5N1NTL%2Fkjnjknjkjk-5.png?alt=media&#x26;token=39308ceb-98bf-4f5e-9d28-3e6485a12ba7" alt=""><figcaption></figcaption></figure>

## 6. Result

<figure><img src="https://3701050178-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6y0J5nnTjSyc65fbCvIU%2Fuploads%2F732E3y8IupnnDFbmW9QX%2Fimage.png?alt=media&#x26;token=42c756be-170a-4bba-a23e-31dfa6b686d4" alt=""><figcaption></figcaption></figure>
