# 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 src = source
	local ped = GetPlayerPed(src)
    local pcoords = GetEntityCoords(ped)
    local PlayerData = QBCore.Players[src].PlayerData
	if PlayerData ~= nil then
		local result = exports.oxmysql:executeSync('SELECT * FROM players WHERE citizenid=@citizenid', {['@citizenid'] = PlayerData.citizenid})
		if result[1] == nil then
			exports.oxmysql:execute('INSERT INTO players (citizenid, cid, license, name, money, charinfo, job, gang, position, metadata) VALUES (:citizenid, :cid, :license, :name, :money, :charinfo, :job, :gang, :position, :metadata, :discordID) 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
			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'] = PlayerData.citizenid,
				['@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),
			})
		end
		-- QBCore.Player.SaveInventory(src)
        	exports['qb-inventory']:SaveInventory(src)
		QBCore.ShowSuccess(GetCurrentResourceName(), 'NEW PLAYER '..PlayerData.name ..' 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(source)
	if PlayerData then
        local ped = GetPlayerPed(source)
        local pcoords = GetEntityCoords(ped)
		local result = exports.oxmysql:executeSync('SELECT * FROM players WHERE citizenid=@citizenid', {['@citizenid'] = PlayerData.citizenid})
		if result[1] == nil then
			exports.oxmysql:execute('INSERT INTO players (citizenid, cid, license, name, money, charinfo, job, gang, position, metadata, discordID) 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
			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'] = PlayerData.citizenid,
				['@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(PlayerData.position),
				['@metadata'] = json.encode(PlayerData.metadata),
			})
		end
		-- QBCore.Player.SaveInventory(src)
        	exports['qb-inventory']:SaveInventory(PlayerData, true)
		QBCore.ShowSuccess(GetCurrentResourceName(), 'NEW PLAYER '..PlayerData.name ..' SAVED!')
	else
		QBCore.ShowError(GetCurrentResourceName(), 'ERROR QBCORE.PLAYER.SAVE - 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 %}


---

# 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://shx-store.gitbook.io/shxstore/~/changes/sWltUEee2euonRDw7ATu/scripts/shx-sid-static-id/installation.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.
