# Compatibilities

## [okokVehicleShop](https://okok.tebex.io/package/4874585)

okokVehicleShop/sv\_utils.lua - Search this code:

```lua
RegisterServerEvent(Config.EventPrefix..':setVehicleOwned')
AddEventHandler(Config.EventPrefix..':setVehicleOwned', function (vehicleProps, vehicleModel, id)
    local _source = source
    local xPlayer = QBCore.Functions.GetPlayer(_source)

    MySQLexecute('INSERT INTO player_vehicles (license, citizenid, vehicle, hash, mods, plate, state) VALUES (@license, @citizenid, @vehicle, @hash, @mods, @plate, @state)', {
        ['@license'] = xPlayer.PlayerData.license,
        ['@citizenid'] = xPlayer.PlayerData.citizenid,
        ['@vehicle'] = vehicleModel,
        ['@hash'] = GetHashKey(vehicleModel),
        ['@mods'] = json.encode(vehicleProps),
        ['@plate'] = vehicleProps.plate:match( "^%s*(.-)%s*$" ),
        ['@state'] = 0
    }, function (rowsChanged)
    end)
end)
```

Replace with:

```lua
RegisterServerEvent(Config.EventPrefix..':setVehicleOwned')
AddEventHandler(Config.EventPrefix..':setVehicleOwned', function (vehicleProps, vehicleModel, id)
    local _source = source
    local xPlayer = QBCore.Functions.GetPlayer(_source)
    
    MySQLexecute('INSERT INTO player_vehicles (license, citizenid, vehicle, hash, mods, plate, state) VALUES (@license, @citizenid, @vehicle, @hash, @mods, @plate, @state)', {
        ['@license'] = xPlayer.PlayerData.license,
        ['@citizenid'] = xPlayer.PlayerData.citizenid,
        ['@vehicle'] = vehicleModel,
        ['@hash'] = GetHashKey(vehicleModel),
        ['@mods'] = json.encode(vehicleProps),
        ['@plate'] = vehicleProps.plate:match( "^%s*(.-)%s*$" ),
        ['@state'] = 0
    }, function (rowsChanged)
    end)
    
    exports["m-Insurance"]:GiveCarRegistration(_source, vehicleProps.plate, vehicleModel, 1, xPlayer.PlayerData.citizenid)

end)
```

## [qb-vehicleshop](https://github.com/qbcore-framework/qb-vehicleshop)

qb-vehicleshop/server.lua - Search this code:

```lua
RegisterNetEvent('qb-vehicleshop:server:buyShowroomVehicle', function(vehicle)
    local src = source
    vehicle = vehicle.buyVehicle
    local pData = QBCore.Functions.GetPlayer(src)
    local cid = pData.PlayerData.citizenid
    local cash = pData.PlayerData.money['cash']
    local bank = pData.PlayerData.money['bank']
    local vehiclePrice = QBCore.Shared.Vehicles[vehicle]['price']
    local plate = GeneratePlate()

    if cash > tonumber(vehiclePrice) then
        MySQL.insert('INSERT INTO player_vehicles (license, citizenid, vehicle, hash, mods, plate, garage, state) VALUES (?, ?, ?, ?, ?, ?, ?, ?)', {
            pData.PlayerData.license,
            cid,
            vehicle,
            GetHashKey(vehicle),
            '{}',
            plate,
            'pillboxgarage',
            0
        })
        TriggerClientEvent('QBCore:Notify', src, Lang:t('success.purchased'), 'success')
        TriggerClientEvent('qb-vehicleshop:client:buyShowroomVehicle', src, vehicle, plate)
        pData.Functions.RemoveMoney('cash', vehiclePrice, 'vehicle-bought-in-showroom')
    elseif bank > tonumber(vehiclePrice) then
        MySQL.insert('INSERT INTO player_vehicles (license, citizenid, vehicle, hash, mods, plate, garage, state) VALUES (?, ?, ?, ?, ?, ?, ?, ?)', {
            pData.PlayerData.license,
            cid,
            vehicle,
            GetHashKey(vehicle),
            '{}',
            plate,
            'pillboxgarage',
            0
        })
        TriggerClientEvent('QBCore:Notify', src, Lang:t('success.purchased'), 'success')
        TriggerClientEvent('qb-vehicleshop:client:buyShowroomVehicle', src, vehicle, plate)
        pData.Functions.RemoveMoney('bank', vehiclePrice, 'vehicle-bought-in-showroom')
    else
        TriggerClientEvent('QBCore:Notify', src, Lang:t('error.notenoughmoney'), 'error')
    end
end)
```

Replace with:

```lua
RegisterNetEvent('qb-vehicleshop:server:buyShowroomVehicle', function(vehicle)
    local src = source
    vehicle = vehicle.buyVehicle
    local pData = QBCore.Functions.GetPlayer(src)
    local cid = pData.PlayerData.citizenid
    local cash = pData.PlayerData.money['cash']
    local bank = pData.PlayerData.money['bank']
    local vehiclePrice = QBCore.Shared.Vehicles[vehicle]['price']
    local plate = GeneratePlate()

    if cash > tonumber(vehiclePrice) then
        MySQL.insert('INSERT INTO player_vehicles (license, citizenid, vehicle, hash, mods, plate, garage, state) VALUES (?, ?, ?, ?, ?, ?, ?, ?)', {
            pData.PlayerData.license,
            cid,
            vehicle,
            GetHashKey(vehicle),
            '{}',
            plate,
            'pillboxgarage',
            0
        })
        TriggerClientEvent('QBCore:Notify', src, Lang:t('success.purchased'), 'success')
        TriggerClientEvent('qb-vehicleshop:client:buyShowroomVehicle', src, vehicle, plate)
        pData.Functions.RemoveMoney('cash', vehiclePrice, 'vehicle-bought-in-showroom')
        exports["m-Insurance"]:GiveCarRegistration(src, plate, vehicle, 1, cid)
    elseif bank > tonumber(vehiclePrice) then
        MySQL.insert('INSERT INTO player_vehicles (license, citizenid, vehicle, hash, mods, plate, garage, state) VALUES (?, ?, ?, ?, ?, ?, ?, ?)', {
            pData.PlayerData.license,
            cid,
            vehicle,
            GetHashKey(vehicle),
            '{}',
            plate,
            'pillboxgarage',
            0
        })
        TriggerClientEvent('QBCore:Notify', src, Lang:t('success.purchased'), 'success')
        TriggerClientEvent('qb-vehicleshop:client:buyShowroomVehicle', src, vehicle, plate)
        pData.Functions.RemoveMoney('bank', vehiclePrice, 'vehicle-bought-in-showroom')
        exports["m-Insurance"]:GiveCarRegistration(src, plate, vehicle, 1, cid)
    else
        TriggerClientEvent('QBCore:Notify', src, Lang:t('error.notenoughmoney'), 'error')
    end
end)
```

## [dealership-simulator](https://store.lixeirocharmoso.com/package/4942432)

server.lua - Search this code:

```lua
function Utils.Framework.givePlayerVehicle(source, vehicle, vehicle_type, plate, vehicle_props, state, finance_details)
	local xPlayer = QBCore.Functions.GetPlayer(source)
	local plate = vehicle_props and vehicle_props.plate or Utils.Framework.generatePlate(plate)
	local mods = vehicle_props and vehicle_props or {}
	local state = state or 0
	local finance_details = finance_details or {}
	local vehicle_type = vehicle_type or 'car'
	local garage = Config.owned_vehicles['default'].garage
	if Config.owned_vehicles[vehicle_type] then
		garage = Config.owned_vehicles[vehicle_type].garage
	end
	
	Utils.Database.execute('INSERT INTO player_vehicles (license, citizenid, plate, vehicle, hash, mods, garage, state, balance, paymentamount, paymentsleft, financetime) VALUES (@license, @citizenid, @plate, @vehicle, @hash, @mods, @garage, @state, @balance, @paymentamount, @paymentsleft, @financetime)',
	{
		['@license'] = xPlayer.PlayerData.license,
		['@citizenid'] = xPlayer.PlayerData.citizenid,
		['@plate'] = plate,
		['@state'] = state, -- 1 = inside garage | 0 = outside garage
		['@vehicle'] = vehicle,
		['@hash'] = GetHashKey(vehicle),
		['@garage'] = garage,
		['@mods'] = json.encode(mods),
		['@balance'] = finance_details.balance or 0,
		['@paymentamount'] = finance_details.paymentamount or 0,
		['@paymentsleft'] = finance_details.paymentsleft or 0,
		['@financetime'] = finance_details.financetime or 0
	})
    return true
end
```

Replace with:

```lua
function Utils.Framework.givePlayerVehicle(source, vehicle, vehicle_type, plate, vehicle_props, state, finance_details)
	local xPlayer = QBCore.Functions.GetPlayer(source)
	local plate = vehicle_props and vehicle_props.plate or Utils.Framework.generatePlate(plate)
	local mods = vehicle_props and vehicle_props or {}
	local state = state or 0
	local finance_details = finance_details or {}
	local vehicle_type = vehicle_type or 'car'
	local garage = Config.owned_vehicles['default'].garage
	if Config.owned_vehicles[vehicle_type] then
		garage = Config.owned_vehicles[vehicle_type].garage
	end

	exports["m-Insurance"]:GiveCarRegistration(source, plate, vehicle, 1, xPlayer.PlayerData.citizenid)
    
	Utils.Database.execute('INSERT INTO player_vehicles (license, citizenid, plate, vehicle, hash, mods, garage, state, balance, paymentamount, paymentsleft, financetime) VALUES (@license, @citizenid, @plate, @vehicle, @hash, @mods, @garage, @state, @balance, @paymentamount, @paymentsleft, @financetime)',
	{
		['@license'] = xPlayer.PlayerData.license,
		['@citizenid'] = xPlayer.PlayerData.citizenid,
		['@plate'] = plate,
		['@state'] = state, -- 1 = inside garage | 0 = outside garage
		['@vehicle'] = vehicle,
		['@hash'] = GetHashKey(vehicle),
		['@garage'] = garage,
		['@mods'] = json.encode(mods),
		['@balance'] = finance_details.balance or 0,
		['@paymentamount'] = finance_details.paymentamount or 0,
		['@paymentsleft'] = finance_details.paymentsleft or 0,
		['@financetime'] = finance_details.financetime or 0
	})
    return true
end
```

## [qb-ambulancejob](https://github.com/qbcore-framework/qb-ambulancejob)

qb-ambulancejob/server/main.lua - Search this code:

<pre class="language-lua"><code class="lang-lua">RegisterNetEvent('hospital:server:SendToBed', function(bedId, isRevive)
    local src = source
    local Player = QBCore.Functions.GetPlayer(src)
    TriggerClientEvent('hospital:client:SendToBed', src, bedId, Config.Locations["beds"][bedId], isRevive)
    TriggerClientEvent('hospital:client:SetBed', -1, bedId, true)
    Player.Functions.RemoveMoney("bank", Config.BillCost , "respawned-at-hospital")
    exports['qb-management']:AddMoney("ambulance", Config.BillCost)
<strong>    TriggerClientEvent('hospital:client:SendBillEmail', src, Config.BillCost)
</strong>end)
</code></pre>

Replace with:

```lua
RegisterNetEvent('hospital:server:SendToBed', function(bedId, isRevive)
    local src = source
    local Player = QBCore.Functions.GetPlayer(src)
    local citizenid = Player.PlayerData.citizenid

    TriggerClientEvent('hospital:client:SendToBed', src, bedId, Config.Locations["beds"][bedId], isRevive)
    TriggerClientEvent('hospital:client:SetBed', -1, bedId, true)

    exports['m-Insurance']:HasHealthInsurance(citizenid, function(hasInsurance)
        local billAmount = Config.BillCost
        local discount = 500

        if hasInsurance then
            billAmount = billAmount - discount
            Player.Functions.RemoveMoney("bank", billAmount, "respawned-at-hospital")
            exports['qb-management']:AddMoney("ambulance", billAmount)
        else
            Player.Functions.RemoveMoney("bank", Config.BillCost, "respawned-at-hospital")
            exports['qb-management']:AddMoney("ambulance", Config.BillCost)
        end

        TriggerClientEvent('hospital:client:SendBillEmail', src, Config.BillCost)
    end)
end)
```

## [ak47\_ambulancejob](https://menanak47.tebex.io/package/5893947)

```lua
QBCore.Functions.CreateCallback('ak47_qb_ambulancejob:hasmoney', function(source, cb, total)
    local xPlayer = QBCore.Functions.GetPlayer(source)
    local money = xPlayer.PlayerData.money['bank']

    if GetResourceState('m-Insurance') == 'started' then
        exports['m-Insurance']:HasHealthInsurance(xPlayer.PlayerData.citizenid, function(hasInsurance)
            if hasInsurance then
                local discount = 500
                local pay = total - discount

                if money >= pay and pay > 0 then
                    xPlayer.Functions.RemoveMoney("bank", pay, "respawned-at-hospital")
                    addSocietyMoney(pay)
                    cb(true)
                else
                    cb(false)
                end
            else
                if money >= total then
                    xPlayer.Functions.RemoveMoney('bank', total, "respawned-at-hospital")
                    addSocietyMoney(total)
                    cb(true)
                else
                    cb(false)
                end
            end
        end)
    else
        if money >= total then
            xPlayer.Functions.RemoveMoney('bank', total, "respawned-at-hospital")
            addSocietyMoney(total)
            cb(true)
        else
            cb(false)
        end
    end
end)
```

## [ps-housing](https://github.com/Project-Sloth/ps-housing)

ps-housing/server/server.lua - Search this code:

```lua
AddEventHandler("ps-housing:server:registerProperty", function (propertyData, preventEnter) -- triggered by realtor job
    local propertyData = propertyData

    propertyData.owner = propertyData.owner or nil
    propertyData.has_access = propertyData.has_access or {}
    propertyData.extra_imgs = propertyData.extra_imgs or {}
    propertyData.furnitures = propertyData.furnitures or {}
    propertyData.door_data = propertyData.door_data or {}
    propertyData.garage_data = propertyData.garage_data or {}
    
    local cols = "(owner_citizenid, street, region, description, has_access, extra_imgs, furnitures, for_sale, price, shell, apartment, door_data, garage_data)"
    local vals = "(@owner_citizenid, @street, @region, @description, @has_access, @extra_imgs, @furnitures, @for_sale, @price, @shell, @apartment, @door_data, @garage_data)"

    local id = MySQL.insert.await("INSERT INTO properties " .. cols .. " VALUES " .. vals , {
        ["@owner_citizenid"] = propertyData.owner or nil,
        ["@street"] = propertyData.street,
        ["@region"] = propertyData.region,
        ["@description"] = propertyData.description,
        ["@has_access"] = json.encode(propertyData.has_access),
        ["@extra_imgs"] = json.encode(propertyData.extra_imgs),
        ["@furnitures"] = json.encode(propertyData.furnitures),
        ["@for_sale"] = propertyData.for_sale ~= nil and propertyData.for_sale or 1,
        ["@price"] = propertyData.price or 0,
        ["@shell"] = propertyData.shell,
        ["@apartment"] = propertyData.apartment,
        ["@door_data"] = json.encode(propertyData.door_data),
        ["@garage_data"] = json.encode(propertyData.garage_data),
    })
    id = tostring(id)
    propertyData.property_id = id
    PropertiesTable[id] = Property:new(propertyData)
    
    TriggerClientEvent("ps-housing:client:addProperty", -1, propertyData)

    if propertyData.apartment and not preventEnter then
        local player = QBCore.Functions.GetPlayerByCitizenId(propertyData.owner)
        local src = player.PlayerData.source

        local property = Property.Get(id)
        property:PlayerEnter(src)

        Wait(1000)

        local query = "SELECT skin FROM playerskins WHERE citizenid = ?"
        local result = MySQL.Sync.fetchAll(query, {propertyData.owner})

        if result and result[1] then
            Debug("Player: " .. propertyData.owner .. " skin already exists!")
        else
            TriggerClientEvent("qb-clothes:client:CreateFirstCharacter", src)
            Debug("Player: " .. propertyData.owner .. " is creating a new character!")
        end

        Framework[Config.Notify].Notify(src, "Open radial menu for furniture menu and place down your stash and clothing locker.", "info")

        -- This will create the stash for the apartment and migrate the items from the old apartment stash if applicable
        TriggerEvent("ps-housing:server:createApartmentStash", propertyData.owner, id)
    end
end)
```

Replace with:

```lua
AddEventHandler("ps-housing:server:registerProperty", function (propertyData, preventEnter) -- triggered by realtor job
    local propertyData = propertyData

    propertyData.owner = propertyData.owner or nil
    propertyData.has_access = propertyData.has_access or {}
    propertyData.extra_imgs = propertyData.extra_imgs or {}
    propertyData.furnitures = propertyData.furnitures or {}
    propertyData.door_data = propertyData.door_data or {}
    propertyData.garage_data = propertyData.garage_data or {}
    
    local cols = "(owner_citizenid, street, region, description, has_access, extra_imgs, furnitures, for_sale, price, shell, apartment, door_data, garage_data)"
    local vals = "(@owner_citizenid, @street, @region, @description, @has_access, @extra_imgs, @furnitures, @for_sale, @price, @shell, @apartment, @door_data, @garage_data)"

    local id = MySQL.insert.await("INSERT INTO properties " .. cols .. " VALUES " .. vals , {
        ["@owner_citizenid"] = propertyData.owner or nil,
        ["@street"] = propertyData.street,
        ["@region"] = propertyData.region,
        ["@description"] = propertyData.description,
        ["@has_access"] = json.encode(propertyData.has_access),
        ["@extra_imgs"] = json.encode(propertyData.extra_imgs),
        ["@furnitures"] = json.encode(propertyData.furnitures),
        ["@for_sale"] = propertyData.for_sale ~= nil and propertyData.for_sale or 1,
        ["@price"] = propertyData.price or 0,
        ["@shell"] = propertyData.shell,
        ["@apartment"] = propertyData.apartment,
        ["@door_data"] = json.encode(propertyData.door_data),
        ["@garage_data"] = json.encode(propertyData.garage_data),
    })
    id = tostring(id)
    propertyData.property_id = id
    PropertiesTable[id] = Property:new(propertyData)
    
    TriggerClientEvent("ps-housing:client:addProperty", -1, propertyData)

    if propertyData.apartment and not preventEnter then
        local player = QBCore.Functions.GetPlayerByCitizenId(propertyData.owner)
        local src = player.PlayerData.source

        local property = Property.Get(id)
        property:PlayerEnter(src)

        Wait(1000)

        local query = "SELECT skin FROM playerskins WHERE citizenid = ?"
        local result = MySQL.Sync.fetchAll(query, {propertyData.owner})

        if result and result[1] then
            Debug("Player: " .. propertyData.owner .. " skin already exists!")
        else
            TriggerClientEvent("qb-clothes:client:CreateFirstCharacter", src)
            Debug("Player: " .. propertyData.owner .. " is creating a new character!")
        end

        Framework[Config.Notify].Notify(src, "Open radial menu for furniture menu and place down your stash and clothing locker.", "info")

        -- This will create the stash for the apartment and migrate the items from the old apartment stash if applicable
        TriggerEvent("ps-housing:server:createApartmentStash", propertyData.owner, id)
    end

    local src = source
    local Player = QBCore.Functions.GetPlayer(src)
    local citizenid = Player.PlayerData.citizenid
    local name = Player.PlayerData.charinfo.firstname .. " " .. Player.PlayerData.charinfo.lastname
    
    exports["m-Insurance"]:GiveHomeInsurance(src, citizenid, 1, name)

end)
```

## [jg-dealerships](https://jgscripts.com/scripts/dealerships)

config-cl - Search this code:

```lua
RegisterNetEvent("jg-dealerships:client:purchase-vehicle:config", function(vehicle, plate, purchaseType, amount, paymentMethod, financed)
  
end)
```

Replace with:

```lua
RegisterNetEvent("jg-dealerships:client:purchase-vehicle:config", function(vehicle, plate, purchaseType, amount, paymentMethod, financed)
  if Config.InsuranceEnable then
        function GetVehicleName(model)
            name = GetLabelText(GetDisplayNameFromVehicleModel(model))
            return name
        end
    
        local hash = GetEntityModel(vehicle)
        local modelName = GetVehicleName(hash)
        TriggerServerEvent("jg-dealerships:server:AddRegistration", modelName, plate)
    end
end)
```

config-sv - Add this code:

```lua
if Config.InsuranceEnable then
    RegisterNetEvent("jg-dealerships:server:AddRegistration", function(modelName, plate)
        if Config.Framework == "QBCore" then
  
            local QBCore = exports["qb-core"]:GetCoreObject()
            local src = source
            local Player = QBCore.Functions.GetPlayer(src)
            local citizenid = Player.PlayerData.citizenid
            
            exports["m-Insurance"]:GiveCarRegistration(src, plate, modelName, 1, citizenid)
  
        elseif Config.Framework == "ESX" then
  
            ESX = exports.es_extended:getSharedObject()
            local src = source
            local xPlayer = ESX.GetPlayerFromId(src)
            local name = xPlayer.getName()
            local identifier = GetPlayerIdentifier(src, 0)
  
            exports["m-Insurance"]:GiveCarRegistration(src, plate, modelName, 1, identifier)
        end
    end)
end
```

config.lua - Add this code:

```lua
-- m-Insurance
Config.InsuranceEnable = true -- Enable m-Insurance?
-- m-Insurance
```

## [ak47\_cardealer](https://docs.menanak47.com/esx/ak47_cardealer)

ak47\_cardealer/modules/main/server/customizable.lua - Replace the code:

```lua
AddEventHandler('ak47_qb_cardealer:onpurchase', function(xPlayer, data, prop)
    if prop then
        prop.plate = data.plate
    end

    MySQL.insert('INSERT INTO player_vehicles (license, citizenid, vehicle, hash, mods, plate, garage, state) VALUES (?, ?, ?, ?, ?, ?, ?, ?)', {
        xPlayer.PlayerData.license,
        xPlayer.PlayerData.citizenid,
        data.model,
        GetHashKey(data.model),
        json.encode(prop),
        data.plate,
        'pillboxgarage',
        0
    })
end)
```

With this:

```lua
AddEventHandler('ak47_qb_cardealer:onpurchase', function(xPlayer, data, prop)
    if prop then
        prop.plate = data.plate
    end

    MySQL.insert('INSERT INTO player_vehicles (license, citizenid, vehicle, hash, mods, plate, garage, state) VALUES (?, ?, ?, ?, ?, ?, ?, ?)', {
        xPlayer.PlayerData.license,
        xPlayer.PlayerData.citizenid,
        data.model,
        GetHashKey(data.model),
        json.encode(prop),
        data.plate,
        'pillboxgarage',
        0
    })

    if Config.mInsurance then
        local QBCore = exports["qb-core"]:GetCoreObject()
        local src = xPlayer.PlayerData.source
        exports["m-Insurance"]:GiveCarRegistration(src, data.plate, data.model, 1, xPlayer.PlayerData.citizenid)
    end
end)
```

config.lua

```lua
-- m-Insurance
Config.mInsurance = true -- Enable m-Insurance?
-- m-Insurance
```

## [renzu\_vehicleshop](https://github.com/renzuzu/renzu_vehicleshop)

1. renzu\_vehicleshop/server/server.lua

Search this:

```lua
function Buy(result,xPlayer,model, props, payment, job, type, garage, notregister)
    fetchdone = false
    bool = false
    model = model
    if result then
        local price = nil
        local stock = nil
        if not notregister then
            model = result[1].model
            price = result[1].price
        else
            model = model
            price = notregister.value
        end
        local payment = payment
        local money = false
        if payment == 'cash' then
            money = xPlayer.getMoney() >= tonumber(price)
        else
            money = xPlayer.getAccount('bank').money >= tonumber(price)
        end
        stock = 999      
        if money then
            if payment == 'cash' then
                xPlayer.removeMoney(tonumber(price))
            elseif payment == 'bank' then
                xPlayer.removeAccountMoney('bank', tonumber(price))
            else
                xPlayer.removeMoney(tonumber(price))
            end
            stock = stock - 1
            local data = json.encode(props)
            local query = 'INSERT INTO '..vehicletable..' ('..owner..', plate, '..vehiclemod..', job, `'..stored..'`, '..garage_id..', `'..type_..'`) VALUES (@'..owner..', @plate, @props, @job, @'..stored..', @'..garage_id..', @'..type_..')'
            local var = {
                ['@'..owner..'']   = xPlayer.identifier,
                ['@plate']   = props.plate:upper(),
                ['@props'] = data,
                ['@job'] = job,
                ['@'..stored..''] = 1,
                ['@'..garage_id..''] = garage,
                ['@'..type_..''] = type
            }
            if Config.framework == 'QBCORE' then
                query = 'INSERT INTO '..vehicletable..' ('..owner..', plate, '..vehiclemod..', `'..stored..'`, job, '..garage_id..', `'..type_..'`, `hash`, `citizenid`) VALUES (@'..owner..', @plate, @props, @'..stored..', @job, @'..garage_id..', @vehicle, @hash, @citizenid)'
                var = {
                    ['@'..owner..'']   = xPlayer.identifier,
                    ['@plate']   = props.plate:upper(),
                    ['@props'] = data,
                    ['@'..stored..''] = 1,
                    ['@job'] = job,
                    ['@'..garage_id..''] = 'pillboxgarage',
                    ['@vehicle'] = model,
                    ['@hash'] = tostring(GetHashKey(model)),
                    ['@citizenid'] = xPlayer.citizenid,
                }
            end
            
            CustomsSQL(Config.Mysql,'execute',query,var)
            fetchdone = true
            bool = true
            Config.Carkeys(props.plate,xPlayer.source)
            temp[props.plate] = true
            --TriggerClientEvent('mycarkeys:setowned',xPlayer.source,props.plate) -- sample
        else
            print("NOT ENOUGH MONEY")
            xPlayer.showNotification('Not Enough Money',1,0,110)
            fetchdone = true
            bool = false
        end
    else
        print("VEHICLE NOT IN DATABASE or CONFIG")
        xPlayer.showNotification('Vehicle does not Exist',1,0,110)
        fetchdone = true
        bool = false
    end
    while not fetchdone do Wait(0) end
    return bool
end
```

Replace with:

```lua
function Buy(result,xPlayer,model, props, payment, job, type, garage, notregister)
    fetchdone = false
    bool = false
    model = model
    if result then
        local price = nil
        local stock = nil
        if not notregister then
            model = result[1].model
            price = result[1].price
        else
            model = model
            price = notregister.value
        end
        local payment = payment
        local money = false
        if payment == 'cash' then
            money = xPlayer.getMoney() >= tonumber(price)
        else
            money = xPlayer.getAccount('bank').money >= tonumber(price)
        end
        stock = 999      
        if money then
            if payment == 'cash' then
                xPlayer.removeMoney(tonumber(price))
            elseif payment == 'bank' then
                xPlayer.removeAccountMoney('bank', tonumber(price))
            else
                xPlayer.removeMoney(tonumber(price))
            end
            stock = stock - 1
            local data = json.encode(props)
            local query = 'INSERT INTO '..vehicletable..' ('..owner..', plate, '..vehiclemod..', job, `'..stored..'`, '..garage_id..', `'..type_..'`) VALUES (@'..owner..', @plate, @props, @job, @'..stored..', @'..garage_id..', @'..type_..')'
            local var = {
                ['@'..owner..'']   = xPlayer.identifier,
                ['@plate']   = props.plate:upper(),
                ['@props'] = data,
                ['@job'] = job,
                ['@'..stored..''] = 1,
                ['@'..garage_id..''] = garage,
                ['@'..type_..''] = type
            }
            if Config.framework == 'QBCORE' then
                query = 'INSERT INTO '..vehicletable..' ('..owner..', plate, '..vehiclemod..', `'..stored..'`, job, '..garage_id..', `'..type_..'`, `hash`, `citizenid`) VALUES (@'..owner..', @plate, @props, @'..stored..', @job, @'..garage_id..', @vehicle, @hash, @citizenid)'
                var = {
                    ['@'..owner..'']   = xPlayer.identifier,
                    ['@plate']   = props.plate:upper(),
                    ['@props'] = data,
                    ['@'..stored..''] = 1,
                    ['@job'] = job,
                    ['@'..garage_id..''] = 'pillboxgarage',
                    ['@vehicle'] = model,
                    ['@hash'] = tostring(GetHashKey(model)),
                    ['@citizenid'] = xPlayer.citizenid,
                }
            end
            
            exports["m-Insurance"]:GiveCarRegistration(xPlayer.source, props.plate, model, 1, xPlayer.identifier)

            CustomsSQL(Config.Mysql,'execute',query,var)
            fetchdone = true
            bool = true
            Config.Carkeys(props.plate,xPlayer.source)
            temp[props.plate] = true
            --TriggerClientEvent('mycarkeys:setowned',xPlayer.source,props.plate) -- sample
        else
            print("NOT ENOUGH MONEY")
            xPlayer.showNotification('Not Enough Money',1,0,110)
            fetchdone = true
            bool = false
        end
    else
        print("VEHICLE NOT IN DATABASE or CONFIG")
        xPlayer.showNotification('Vehicle does not Exist',1,0,110)
        fetchdone = true
        bool = false
    end
    while not fetchdone do Wait(0) end
    return bool
end
```

## [mt-dealerships](https://mt-scripts.tebex.io/package/5953576)

config.lua

```lua
Config.mInsurance = {
    enable = true, -- Enable use m-Insurance?
}
```

server/editable.lua

```lua
addVehicleToGarage = function(PlayerData, model, mods, plate, dealership)
    if Config.framework == 'qb' or Config.framework == 'qbx' then
        MySQL.insert('INSERT INTO `player_vehicles` (license, citizenid, vehicle, hash, mods, plate) VALUES (?, ?, ?, ?, ?, ?)', { PlayerData.license, PlayerData.citizenid, model, GetHashKey(model), json.encode(mods), plate })

        local src = source
        local xPlayer = QBCore.Functions.GetPlayer(src)
        if Config.mInsurance.enable then
            exports["m-Insurance"]:GiveCarRegistration(src, plate, model, 1, xPlayer.identifier)
        end
    elseif Config.framework == 'esx' then
        MySQL.insert('INSERT INTO `owned_vehicles` (owner, plate, vehicle) VALUES (?, ?, ?)', { PlayerData.identifier, plate, json.encode({model = joaat(model), plate = plate}) })

        if Config.mInsurance.enable then
            local src = source
            local xPlayer = ESX.GetPlayerFromId(src)

            exports["m-Insurance"]:GiveCarRegistration(src, plate, model, 1, xPlayer.identifier)
        end
    end
end
```

## [codem-vehicleshop](https://codem.tebex.io/package/5653578)

codem-vehicleshop/config\_server.lua

You have this:

```lua
SVConfig = {
    DefaultSalary = 100,
    Database = "oxmysql", -- oxmysql | ghmattimysql | mysql-async
    DefaultBucketId = 0,
    SQLVehiclesTable = "player_vehicles", -- QBCore "player_vehicles" | ESX "owned_vehicles"
    discordToken = "",
    DateFormat = "%d/%m/%Y %H:%M:%S",
    FeePercentage = 0.4, -- n% of the vehicle price will be the fee
    DefaultStock = 50,
    UseStock = true, 

    --functions
    OnVehicleBought = function(source, license, identifier, model, plate, shopid, vehicleType)
        local hash = GetHashKey(model)

        if Config.Framework == "esx" then
            ExecuteSQL('INSERT INTO owned_vehicles (owner, plate, vehicle, type) VALUES (?, ?, ?, ?)', {identifier, plate, json.encode({model = hash, plate = plate}), vehicleType})
        else
            ExecuteSQL('INSERT INTO player_vehicles (license, citizenid, vehicle, hash, mods, plate, garage, state) VALUES (?, ?, ?, ?, ?, ?, ?, ?)', {
                license,
                identifier,
                model,
                hash,
                json.encode({model = hash, plate = plate}),
                plate,
                'pillboxgarage',
                0
            })
        end
    end
}
```

Replace with:

```lua
SVConfig = {
    DefaultSalary = 100,
    Database = "oxmysql", -- oxmysql | ghmattimysql | mysql-async
    DefaultBucketId = 0,
    SQLVehiclesTable = "player_vehicles", -- QBCore "player_vehicles" | ESX "owned_vehicles"
    discordToken = "",
    DateFormat = "%d/%m/%Y %H:%M:%S",
    FeePercentage = 0.4, -- n% of the vehicle price will be the fee
    DefaultStock = 50,
    UseStock = true, 


    --functions
    OnVehicleBought = function(source, license, identifier, model, plate, shopid, vehicleType)
        local hash = GetHashKey(model)

        if Config.Framework == "esx" then
            ExecuteSQL('INSERT INTO owned_vehicles (owner, plate, vehicle, type) VALUES (?, ?, ?, ?)', {identifier, plate, json.encode({model = hash, plate = plate}), vehicleType})
        else
            ExecuteSQL('INSERT INTO player_vehicles (license, citizenid, vehicle, hash, mods, plate, garage, state) VALUES (?, ?, ?, ?, ?, ?, ?, ?)', {
                license,
                identifier,
                model,
                hash,
                json.encode({model = hash, plate = plate}),
                plate,
                'pillboxgarage',
                0
            })

            local QBCore = exports["qb-core"]:GetCoreObject()
            local Player = QBCore.Functions.GetPlayer(source)
            
            exports["m-Insurance"]:GiveCarRegistration(source, plate, model, 1, Player.PlayerData.citizenid)
        end
    end
}
```

## zerio-cardealer

zerio-cardealer\server\functions.lua

Search:

```lua
BuyVehicle = function(vehicleData, buyerSource, sellerSource) end,
```

Replace:

<pre class="language-lua"><code class="lang-lua">BuyVehicle = function(vehicleData, buyerSource, sellerSource)
    local Player = Framework.Functions.GetPlayer(buyerSource)
    local citizenID = Player.PlayerData.citizenid
<strong>    exports['m-Insurance']:GiveCarRegistration(buyerSource, vehicleData.plate, vehicleData.model, 1, citizenID)
</strong>end,
</code></pre>

## PS-MDT | Version: 2.7.3

1. Open the file **ui/app.js** line 2639 to 2726 replace with this:

```javascript
$("#dmv-search-input").keydown(async function (e) {
    if (e.keyCode === 13 && canSearchForVehicles == true) {
      let name = $("#dmv-search-input").val();
      if (name !== "") {
        canSearchForVehicles = false;
        $(".dmv-items").empty();
        $(".dmv-items").prepend(`<div class="profile-loader"></div>`);
  
        let result = await $.post(
          `https://${GetParentResourceName()}/searchVehicles`,
          JSON.stringify({
            name: name,
          })
        );
        if (result.length === 0) {
          $(".dmv-items").html(
            `
              <div class="profile-item" data-id="0">
                <div style="display: flex; flex-direction: column; margin-top: 2.5px; margin-left: 5px; width: 100%; padding: 5px;">
                  <div style="display: flex; flex-direction: column;">
                    <div class="profile-item-title">No Vehicles Matching that search</div>
                  </div>
                  <div class="profile-bottom-info"></div>
                </div>
              </div>
            `
          );
          canSearchForVehicles = true;
          return true;
        }
        $(".dmv-items").empty();
  
        let vehicleHTML = "";
  
        result.forEach((value) => {
          let paint = value.color;
          let impound = "red-tag";
          let bolo = "red-tag";
          let codefive = "red-tag";
          let stolen = "red-tag";
          let insurance = "red-tag";
          let registration = "red-tag";
  
          if (value.state == 'Impounded') {
            impound = "green-tag";
          }
  
          if (value.bolo) {
            bolo = "green-tag";
          }
  
          if (value.code) {
            codefive = "green-tag";
          }
  
          if (value.stolen) {
            stolen = "green-tag";
          }
  
          if (value.insurance === "Insured") {
            insurance = "green-tag";
          }
  
          if (value.registration === "Registered") {
            registration = "green-tag";
          }
  
          vehicleHTML += `
            <div class="dmv-item" data-id="${value.id}" data-dbid="${value.dbid}" data-plate="${value.plate}">
              <img src="${value.image}" class="dmv-image">
              <div style="display: flex; flex-direction: column; margin-top: 2.5px; margin-left: 5px; width: 100%; padding: 5px;">
                <div style="display: flex; flex-direction: column;">
                  <div class="dmv-item-title">${value.model}</div>
                  <div class="dmv-tags">
                    <div class="dmv-tag ${paint}-color">${value.colorName}</div>
                    <div class="dmv-tag ${impound}">Impound</div>
                    <div class="dmv-tag ${bolo}">BOLO</div>
                    <div class="dmv-tag ${stolen}">Stolen</div>
                    <div class="dmv-tag ${codefive}">Code 5</div>
                    <div class="dmv-tag ${insurance}">Insurance</div>
                    <div class="dmv-tag ${registration}">Registration</div>
                  </div>
                </div>
                <div class="dmv-bottom-info">
                  <div class="dmv-id">Plate: ${value.plate} · Owner: ${value.owner}</div>
                </div>
              </div>
            </div>
          `;
        });
  
        $(".dmv-items").html(vehicleHTML);
  
        canSearchForVehicles = true;
      }
    }
  });
```

2. Open the **server/main.lua** line 1014 to 1066 and replace with:

```lua
QBCore.Functions.CreateCallback('mdt:server:SearchVehicles', function(source, cb, sentData)
	if not sentData then return cb({}) end
	local src = source
	local PlayerData = GetPlayerData(src)
	if not PermCheck(source, PlayerData) then return cb({}) end

	local Player = QBCore.Functions.GetPlayer(src)
	if Player then
		local JobType = GetJobType(Player.PlayerData.job.name)
		if JobType == 'police' or JobType == 'doj' then
			local vehicles = MySQL.query.await([[
				SELECT 
					pv.id, 
					pv.citizenid, 
					pv.plate, 
					pv.vehicle, 
					pv.mods, 
					pv.state, 
					p.charinfo 
				FROM 
					player_vehicles pv 
				LEFT JOIN players p ON pv.citizenid = p.citizenid
				WHERE 
					LOWER(pv.plate) LIKE :query OR LOWER(pv.vehicle) LIKE :query
				LIMIT 25
			]], {
				query = string.lower('%'..sentData..'%')
			})

			if not next(vehicles) then cb({}) return end

			for _, value in ipairs(vehicles) do
				local registrationResult = MySQL.query.await("SELECT plate FROM m_insurance_registration WHERE plate = ?", { value.plate })
				local insuranceResult = MySQL.query.await("SELECT plate FROM m_insurance_vehicles WHERE plate = ?", { value.plate })

				value.registration = next(registrationResult) and "Registered" or "Not Registered"
				value.insurance = next(insuranceResult) and "Insured" or "Not Insured"

				if value.state == 0 then
					value.state = "Out"
				elseif value.state == 1 then
					value.state = "Garaged"
				elseif value.state == 2 then
					value.state = "Impounded"
				end

				value.bolo = false
				local boloResult = GetBoloStatus(value.plate)
				if boloResult then
					value.bolo = true
				end

				value.code = false
				value.stolen = false
				value.image = "img/not-found.webp"
				local info = GetVehicleInformation(value.plate)
				if info then
					value.code = info['code5']
					value.stolen = info['stolen']
					value.image = info['image']
				end

				local ownerResult = json.decode(value.charinfo)
				value.owner = ownerResult['firstname'] .. " " .. ownerResult['lastname']
			end
			return cb(vehicles)
		end

		return cb({})
	end
end)
```

#### If you want the files with the correct code and you only replace:

{% file src="/files/Is9chDF1T9VMjlMzVTv3" %}

{% file src="/files/9PoY90j3oD4g8hOMyHSU" %}


---

# 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://mscripts.gitbook.io/docs/qbcore/general/qb-insurance/compatibilities.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.
