# Add SSN Generation

***

{% hint style="danger" %}

## READ IT!

**This section is only for ESX users!**
{% endhint %}

1. ### Adjust SSN format

Go to **vms\_cityhall/server/modules/ssn.lua** and in the first line you have to customize your birth date format stored on your server.

By default, the date of birth in ESX is stored in the column **dateofbirth**.

<figure><img src="https://3701050178-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6y0J5nnTjSyc65fbCvIU%2Fuploads%2Fwqq1xdXjqj7Xak7KgDW8%2Fimage.png?alt=media&#x26;token=4d7b3fa6-72ba-4062-bfef-602298295737" alt=""><figcaption><p><em><strong>vms_cityhall/server/modules/ssn.lua</strong></em></p></figcaption></figure>

2. ### Modifications in es\_extended

{% hint style="warning" %}
**If you are NOT using any multicharacter system, skip this step, go to identity.**
{% endhint %}

Go to your es\_extended/server/main.lua and replace the highlighted code in the `createESXPlayer` function.&#x20;

<pre class="language-lua" data-title="es_extended/server/main.lua" data-full-width="false" data-expandable="true"><code class="lang-lua">local function createESXPlayer(identifier, playerId, data)
    local accounts = {}

    for account, money in pairs(Config.StartingAccountMoney) do
        accounts[account] = money
    end

    local defaultGroup = "user"
    if Core.IsPlayerAdmin(playerId) then
        print(("[^2INFO^0] Player ^5%s^0 Has been granted admin permissions via ^5Ace Perms^7."):format(playerId))
        defaultGroup = "admin"
    end
    local parameters = Config.Multichar and
<strong>        { json.encode(accounts), identifier, Core.generateSSN(data.dateofbirth, data.sex), defaultGroup, data.firstname, data.lastname, data.dateofbirth, data.sex, data.height }
</strong>        or { json.encode(accounts), identifier, Core.generateSSN(), defaultGroup }

    if Config.StartingInventoryItems then
        table.insert(parameters, json.encode(Config.StartingInventoryItems))
    end

    MySQL.prepare(newPlayer, parameters, function()
        loadESXPlayer(identifier, playerId, true)
    end)
end
</code></pre>

Find the `loadESXPlayer` function and only the highlighted code

{% hint style="info" %}
Part of the code from the `loadESXPlayer` function has been removed to focus on the required changes.

You need to enter only `xPlayer.set("ssn", result.ssn)` in the highlighted area.

The line: `xPlayer.set("ssn", result.ssn)`

**MUST be placed:**

* inside `loadESXPlayer()`
* after the Identity block
* before `TriggerEvent("esx:playerLoaded")`
  {% endhint %}

<pre class="language-lua"><code class="lang-lua">function loadESXPlayer(identifier, playerId, isNew)
    ...

    -- Identity
    if result.firstname and result.firstname ~= "" then
        ...
    end
    
<strong>    xPlayer.set("ssn", result.ssn)
</strong>
    TriggerEvent("esx:playerLoaded", playerId, xPlayer, isNew)
    
    ....
end
</code></pre>

Go to your es\_extended/server/functions.lua and replace the entire `Core.generateSSN` function.&#x20;

{% code title="es\_extended/server/functions.lua" expandable="true" %}

```lua
---@param dob string?
---@param sex number?
---@return number
function Core.generateSSN(dob, sex)
    if dob == nil or sex == nil then
        return nil
    end
    
    if GetResourceState('vms_cityhall') == 'started' then
        return exports['vms_cityhall']:GenerateSSN(dob, sex)
    elseif GetResourceState('vms_documentsv2') == 'started' then
        return exports['vms_documentsv2']:GenerateSSN(dob, sex)
    end
end
```

{% endcode %}

3. ### Modifications in esx\_identity

{% hint style="warning" %}
**If you are using any multicharacter go back to point two.**
{% endhint %}

If you don't want to use the whole esx\_identity, read carefully the [**README.md**](https://github.com/vames-dev/es_extended/blob/main/README.md) from the above github, there you will find exactly marked changes.

{% embed url="<https://github.com/vames-dev/esx_identity>" %}
