# Compatibilities

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

{% tabs %}
{% tab title="config.lua" %}

```lua
Config.mScripts = {
  insurance = true, -- Enable insurance integration with mScripts Insurance System
  courtsystem = true, -- Enable tax calculation integration with m-CourtSystem
}
```

{% endtab %}

{% tab title="config-cl.lua" %}

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

{% endtab %}

{% tab title="config-sv.lua" %}

```lua
RegisterNetEvent("jg-dealerships:server:purchase-vehicle:config", function(vehNetId, plate, purchaseType, amount, paymentMethod, financed)
    local src = source

    if Config.mScripts.courtsystem then
        local tax = exports['m-CourtSystem']:GetTax("vehicles", amount)

        if (Config.Framework == "auto" and (GetResourceState("qb-core") == "started" or GetResourceState("qbx_core") == "started")) or Config.Framework == "QBCore" or Config.Framework == "Qbox" then
            local QBCore = exports['qb-core']:GetCoreObject()
            local Player = QBCore.Functions.GetPlayer(src)
            if Player then
                if paymentMethod == "bank" then
                    if Player.PlayerData.money.bank >= tax then
                        Player.Functions.RemoveMoney("bank", tax)
                        Framework.Server.Notify(src, "You have purchased the vehicle, tax applied of $"..tax, "success")
                    else
                        Framework.Server.Notify(src, "You do not have enough money in the bank to pay the tax", "error")
                    end
                elseif paymentMethod == "cash" then
                    if Player.PlayerData.money.cash >= tax then
                        Player.Functions.RemoveMoney("cash", tax)
                        Framework.Server.Notify(src, "You have purchased the vehicle, tax applied of $"..tax, "success")
                    else
                        Framework.Server.Notify(src, "You do not have enough money in cash to pay the tax", "error")
                    end
                end
            end

        elseif (Config.Framework == "auto" and GetResourceState("es_extended") == "started") or Config.Framework == "ESX" then
            local ESX = exports.es_extended:getSharedObject()
            local xPlayer = ESX.GetPlayerFromId(src)
            if xPlayer then
                if paymentMethod == "bank" then
                    if xPlayer.getAccount('bank').money >= tax then
                        xPlayer.removeAccountMoney('bank', tax)
                        Framework.Server.Notify(src, "You have purchased the vehicle, tax applied of $"..tax, "success")
                    else
                        Framework.Server.Notify(src, "You do not have enough money in the bank to pay the tax", "error")
                    end
                elseif paymentMethod == "cash" then
                    if xPlayer.getMoney() >= tax then
                        xPlayer.removeMoney(tax)
                        Framework.Server.Notify(src, "You have purchased the vehicle, tax applied of $"..tax, "success")
                    else
                        Framework.Server.Notify(src, "You do not have enough money in cash to pay the tax", "error")
                    end
                end
            end
        end
    end
end)

RegisterNetEvent("jg-dealerships:server:give-insurance", function(modelName, plate)
    local src = source

    if (Config.Framework == "auto" and (GetResourceState("qb-core") == "started" or GetResourceState("qbx_core") == "started")) 
        or Config.Framework == "QBCore" or Config.Framework == "Qbox" then
        
        local QBCore = exports["qb-core"]:GetCoreObject()
        local Player = QBCore.Functions.GetPlayer(src)
        if Player then
            local citizenid = Player.PlayerData.citizenid
            exports["m-Insurance"]:GiveCarRegistration(src, plate, modelName, 1, citizenid)
        end

    elseif (Config.Framework == "auto" and GetResourceState("es_extended") == "started") or Config.Framework == "ESX" then
        local ESX = exports.es_extended:getSharedObject()
        local xPlayer = ESX.GetPlayerFromId(src)
        if xPlayer then
            local identifier = GetPlayerIdentifier(src, 0)
            exports["m-Insurance"]:GiveCarRegistration(src, plate, modelName, 1, identifier)
        end
    end
end)
```

{% endtab %}
{% endtabs %}
