# Installation

## qb-core

You have to go here and find this. qb-core/server/player.lua find `QBCore.Player.Save(source)` and change :

{% code title="qb-core/server/player.lua" %}

```lua
function QBCore.Player.Save(source)
    local ped = GetPlayerPed(source)
    local pcoords = GetEntityCoords(ped)
    local PlayerData = QBCore.Players[source].PlayerData
    if PlayerData then
        local result = MySQL.query.await('SELECT * FROM players WHERE citizenid=@citizenid', {['@citizenid'] = PlayerData.citizenid})
        if result[1] == nil then
            MySQL.insert('INSERT INTO players (citizenid, cid, license, name, money, charinfo, job, gang, position, metadata) VALUES (:citizenid, :cid, :license, :name, :money, :charinfo, :job, :gang, :position, :metadata) ON DUPLICATE KEY UPDATE cid = :cid, name = :name, money = :money, charinfo = :charinfo, job = :job, gang = :gang, position = :position, metadata = :metadata', {
                citizenid = PlayerData.citizenid,
                cid = tonumber(PlayerData.cid),
                license = PlayerData.license,
                name = PlayerData.name,
                money = json.encode(PlayerData.money),
                charinfo = json.encode(PlayerData.charinfo),
                job = json.encode(PlayerData.job),
                gang = json.encode(PlayerData.gang),
                position = json.encode(pcoords),
                metadata = json.encode(PlayerData.metadata)
            })
        else
            MySQL.update("UPDATE players SET license = ?, name = ?, money = ?, charinfo = ?, job = ?, gang = ?, position = ?, metadata = ?", {
                PlayerData.license,
                PlayerData.name,
                json.encode(PlayerData.money),
                json.encode(PlayerData.charinfo),
                json.encode(PlayerData.job),
                json.encode(PlayerData.gang),
                json.encode(pcoords),
                json.encode(PlayerData.metadata),
            })
        end
        if GetResourceState('qb-inventory') ~= 'missing' then exports['qb-inventory']:SaveInventory(source) end
        QBCore.ShowSuccess(GetCurrentResourceName(), PlayerData.name .. ' PLAYER SAVED!')
    else
        QBCore.ShowError(GetCurrentResourceName(), 'ERROR QBCORE.PLAYER.SAVE - PLAYERDATA IS EMPTY!')
    end
end
```

{% endcode %}

**After change:** You have to go here and find this. qb-core/server/player.lua find `QBCore.Player.SaveOffline(source)`

{% code title="qb-core/server/player.lua" %}

```lua
function QBCore.Player.SaveOffline(PlayerData)
    if PlayerData then
        local result = MySQL.query.await('SELECT * FROM players WHERE citizenid=@citizenid', {['@citizenid'] = PlayerData.citizenid})
        if result[1] == nil then
            MySQL.insert('INSERT INTO players (citizenid, cid, license, name, money, charinfo, job, gang, position, metadata) VALUES (:citizenid, :cid, :license, :name, :money, :charinfo, :job, :gang, :position, :metadata) ON DUPLICATE KEY UPDATE cid = :cid, name = :name, money = :money, charinfo = :charinfo, job = :job, gang = :gang, position = :position, metadata = :metadata', {
                citizenid = PlayerData.citizenid,
                cid = tonumber(PlayerData.cid),
                license = PlayerData.license,
                name = PlayerData.name,
                money = json.encode(PlayerData.money),
                charinfo = json.encode(PlayerData.charinfo),
                job = json.encode(PlayerData.job),
                gang = json.encode(PlayerData.gang),
                position = json.encode(pcoords),
                metadata = json.encode(PlayerData.metadata)
            })
        else
            MySQL.update("UPDATE players SET license = ?, name = ?, money = ?, charinfo = ?, job = ?, gang = ?, position = ?, metadata = ?", {
                PlayerData.license,
                PlayerData.name,
                json.encode(PlayerData.money),
                json.encode(PlayerData.charinfo),
                json.encode(PlayerData.job),
                json.encode(PlayerData.gang),
                json.encode(pcoords),
                json.encode(PlayerData.metadata),
            })
        end
        if GetResourceState('qb-inventory') ~= 'missing' then exports['qb-inventory']:SaveInventory(PlayerData, true) end
        QBCore.ShowSuccess(GetCurrentResourceName(), PlayerData.name .. ' OFFLINE PLAYER SAVED!')
    else
        QBCore.ShowError(GetCurrentResourceName(), 'ERROR QBCORE.PLAYER.SAVEOFFLINE - PLAYERDATA IS EMPTY!')
    end
end
```

{% endcode %}

## **qbx-core**

You have to go here and find this. qbx-core/server/storage.lua find `UpsertPlayerEntity(request)`and change :

{% code title="qbx-core/server/storage.lua" %}

```lua
function UpsertPlayerEntity(request)
    local src = source
    local result = exports.oxmysql:executeSync('SELECT * FROM players WHERE citizenid=@citizenid', {['@citizenid'] = request.playerEntity.citizenid})
    if result[1] == nil then
        MySQL.query.await('INSERT INTO players (citizenid, license, name, money, charinfo, job, gang, position, metadata) VALUES (:citizenid, :license, :name, :money, :charinfo, :job, :gang, :position, :metadata) ON DUPLICATE KEY UPDATE name = :name, money = :money, charinfo = :charinfo, job = :job, gang = :gang, position = :position, metadata = :metadata', {
            citizenid = request.playerEntity.citizenid,
            license = request.playerEntity.license,
            name = request.playerEntity.name,
            money = json.encode(request.playerEntity.money),
            charinfo = json.encode(request.playerEntity.charinfo),
            job = json.encode(request.playerEntity.job),
            gang = json.encode(request.playerEntity.gang),
            position = json.encode(request.position),
            metadata = json.encode(request.playerEntity.metadata)
        })
    else
        exports.oxmysql:execute('UPDATE players SET license = @license, name = @name, money = @money, charinfo = @charinfo, job = @job, gang = @gang, position = @position, metadata = @metadata WHERE citizenid = @citizenid', {
            ['@citizenid'] = request.playerEntity.citizenid,
            ['@license'] = request.playerEntity.license,
            ['@name'] = request.playerEntity.name,
            ['@money'] = json.encode(request.playerEntity.money),
            ['@charinfo'] = json.encode(request.playerEntity.charinfo),
            ['@job'] = json.encode(request.playerEntity.job),
            ['@gang'] = json.encode(request.playerEntity.gang),
            ['@position'] = json.encode(request.position),
            ['@metadata'] = json.encode(request.playerEntity.metadata),
        })
    end
end
```

{% endcode %}
