#qb police depot

1 messages · Page 1 of 1 (latest)

honest cliff
#

SQL

ALTER TABLE player_vehicles
ADD COLUMN depot_end_dt DATETIME NULL DEFAULT NULL;

#

police:client:ImpoundVehicle


RegisterNetEvent('police:client:ImpoundVehicle', function(fullImpound)
    local dialog = exports['qb-input']:ShowInput({
        header = Lang:t('info.tow_vehicle'),
        submitText = Lang:t('menu.confirm'),
        inputs = {
            {
                text = Lang:t('info.amount'), 
                name = "price",
                type = "number",
                isRequired = true,
                default = 0,
            },
            {
                text = Lang:t('info.impound_days'),  
                name = "days",
                type = "number",
                isRequired = false,
                default = 0,
            }
        }
    })

    if dialog then
        local vehicle = QBCore.Functions.GetClosestVehicle()
        if not vehicle or vehicle == 0 then
            TriggerEvent('QBCore:Notify', Lang:t('error.no_vehicle'), 'error')
            return
        end

        local bodyDamage   = math.ceil(GetVehicleBodyHealth(vehicle))
        local engineDamage = math.ceil(GetVehicleEngineHealth(vehicle))
        local totalFuel    = exports[Config.FuelScript]:GetFuel(vehicle)
        local price        = tonumber(dialog.price) or 0
        if price < 0 then price = 0 end
        local days         = tonumber(dialog.days) or 0
        if days < 0 then days = 0 end

        local ped = PlayerPedId()
        local pos = GetEntityCoords(ped)
        local vehpos = GetEntityCoords(vehicle)
        if #(pos - vehpos) < 5.0 and not IsPedInAnyVehicle(ped) then
            QBCore.Functions.Progressbar('impound', Lang:t('progressbar.impound'), 5000, false, true, {
                disableMovement = true,
                disableCarMovement = true,
                disableMouse = false,
                disableCombat = true,
            }, {
                animDict = 'missheistdockssetup1clipboard@base',
                anim = 'base',
                flags = 1,
            }, {
                model = 'prop_notepad_01',
                bone = 18905,
                coords = { x = 0.1, y = 0.02, z = 0.05 },
                rotation = { x = 10.0, y = 0.0, z = 0.0 },
            }, {
                model = 'prop_pencil_01',
                bone = 58866,
                coords = { x = 0.11, y = -0.02, z = 0.001 },
                rotation = { x = -120.0, y = 0.0, z = 0.0 },
            }, function()
                local plate = QBCore.Functions.GetPlate(vehicle)
                TriggerServerEvent("police:server:Impound", plate, fullImpound, price, bodyDamage, engineDamage, totalFuel, days)
               
                while NetworkGetEntityOwner(vehicle) ~= 128 do  
                    NetworkRequestControlOfEntity(vehicle)
                    Wait(100)
                end
                QBCore.Functions.DeleteVehicle(vehicle)
                TriggerEvent('QBCore:Notify', Lang:t('success.impounded'), 'success')
                ClearPedTasks(ped)
            end, function()
                ClearPedTasks(ped)
                TriggerEvent('QBCore:Notify', Lang:t('error.canceled'), 'error')
            end)
        else
            TriggerEvent('QBCore:Notify', Lang:t('error.toofar'), 'error')
        end
    end
end)

#

police:server:Impound


RegisterNetEvent('police:server:Impound', function(plate, fullImpound, price, body, engine, fuel, days)
    local src = source
    price = price or 0
    days = tonumber(days) or 0  -- 確保 days 是數字

    if IsVehicleOwned(plate) then
        -- 使用 DATETIME 格式存入扣押結束時間,若 days 為 0 則表示永久扣押(NULL)
        local depotEndDate = nil
        if days > 0 then
            depotEndDate = os.date("%Y-%m-%d %H:%M:%S", os.time() + (days * 86400))  -- 86400 秒 = 1 天
        end

        if not fullImpound then
            MySQL.query(
                'UPDATE player_vehicles SET state = ?, depotprice = ?, body = ?, engine = ?, fuel = ?, depot_end_dt = ? WHERE plate = ?',
                {0, price, body, engine, fuel, depotEndDate, plate}
            )
            TriggerClientEvent('QBCore:Notify', src, Lang:t("info.vehicle_taken_depot", {price = price, days = days}))
        else
            MySQL.query(
                'UPDATE player_vehicles SET state = ?, depotprice = ?, body = ?, engine = ?, fuel = ?, depot_end_dt = ? WHERE plate = ?',
                {2, price, body, engine, fuel, depotEndDate, plate}
            )
            TriggerClientEvent('QBCore:Notify', src, Lang:t("info.vehicle_seized", {price = price, days = days}))
        end
    end
end)