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 2. Document registration.

  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:

Adjust all parameters for the document and create an item in your inventory.

Create a New Document
['weapon_license'] = {
    type = 'document', 
    itemName = 'weapon_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'
    },
    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).


3. Introduction of new player data information

SV.getDocumentsData obtains information from the data you have implemented in the section of the Create a New Document enter new parameters if any have been added.

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

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

For this document we need firstName, lastName, ssn and height.

  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.

Adding missing value to the SV.getDocumentsData
['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
},

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.

Adding missing function to the SV.getPlayerData
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


4. Introduction of new player licenses information

SV.getDocumentsLicense obtains information from the licenses you have implemented in the section Create a New Document enter new parameters if any have been added.

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

licenses = {
    'weapon'
},

For this document we need a weapon.

  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.

Adding missing license to the SV.getDocumentsLicense
['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,
},

5. Customizing the displayed data

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.

// 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

// Example:
returnVal.push({
    type: "data2",
    label: "Badge number:",
    value: data['badgeNumber']
})
  • signature: Handwrite font signature visible on the document.

// Example:
returnVal.push({
    type: "signature",
    value: data['firstName'] + ' ' + data['lastName']
})
  • document_name: Document name displayed at the top of the document.

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

  1. Open metadata.js

  2. Register a new document: You need to enter the data to be displayed on the document

Register a new document
} 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"
    })
}

6. Result

Last updated