local QBCore = exports['qb-core']:GetCoreObject() local function TranferVeh() local MyVeh = lib.callback.await('alizadev-vehicletransfer:server:GetMyVehicles', false) if MyVeh then local Menu = {} for i in pairs(MyVeh) do if QBCore.Shared.Vehicles[MyVeh[i].vehicle] then local VehShar = QBCore.Shared.Vehicles[MyVeh[i].vehicle] local VehFullName = VehShar.brand..' '..VehShar.name Menu[#Menu +1] = { title = VehFullName, icon = 'car-side', onSelect = function() local Veh, Distance = QBCore.Functions.GetClosestVehicle() if Veh ~= 0 and Distance < 5.0 then local Plate = QBCore.Functions.GetPlate(Veh) if Plate ~= MyVeh[i].plate then QBCore.Functions.Notify(Config.Locales['vehicle_not_yours'], 'error', 6000) return end local VehInput = lib.inputDialog(Config.Locales['input_dialog_title'], { {type = 'number', label = Config.Locales['input_player_id'], icon = 'address-card', required = true, min = 1, max = 20000}, {type = 'number', label = Config.Locales['input_price'], icon = 'tag', required = true}, {type = 'checkbox', label = Config.Locales['input_confirm'], required = true}, }) if VehInput then if Config.LimitPrice.MaxPrice < tonumber(VehInput[2]) then QBCore.Functions.Notify(string.format(Config.Locales['max_price_limit'], Config.LimitPrice.MaxPrice), 'error') TranferVeh() return elseif Config.LimitPrice.MinPrice > tonumber(VehInput[2]) then QBCore.Functions.Notify(string.format(Config.Locales['min_price_limit'], Config.LimitPrice.MinPrice), 'error') TranferVeh() return end local player = GetPlayerFromServerId(VehInput[1]) local myId = GetPlayerServerId(PlayerId()) if not Config.EnableTransferSelf then if myId == VehInput[1] then QBCore.Functions.Notify(Config.Locales['cannot_self_transfer'], 'error') return end end if player and player ~= -1 then local ped = PlayerPedId() local tPed = GetPlayerPed(player) local dist = #(GetEntityCoords(ped) - GetEntityCoords(tPed)) <= 5 if dist then local tInfo = lib.callback.await('alizadev-vehicletransfer:server:GetPlayerInfo', false, VehInput[1]) if not tInfo then QBCore.Functions.Notify(Config.Locales['player_not_active'], 'error') return end local alert = lib.alertDialog({ header = string.format(Config.Locales['seller_confirmation_header'], VehFullName, MyVeh[i].plate, tInfo.FullName, VehInput[2]), centered = true, cancel = true }) if alert == 'confirm' then TriggerServerEvent('alizadev-vehicletransfer:server:Confirmation:TransferVeh', tonumber(VehInput[1]), tonumber(VehInput[2]), VehFullName, MyVeh[i].plate, MyVeh[i].vehicle) elseif alert == 'cancel' then lib.showContext('transfer_vehicle_menu') end else QBCore.Functions.Notify(Config.Locales['player_not_nearby'], 'error') end else QBCore.Functions.Notify(Config.Locales['player_not_active'], 'error') end end else QBCore.Functions.Notify(Config.Locales['vehicle_not_nearby'], 'error') end end } end end lib.registerContext({ id = 'transfer_vehicle_menu', title = Config.Locales['transfer_menu_title'], options = Menu }) lib.showContext('transfer_vehicle_menu') else QBCore.Functions.Notify(Config.Locales['no_vehicles'], 'error', 4000) end end RegisterNetEvent('alizadev-vehicletransfer:client:TransferVeh', TranferVeh) RegisterNetEvent('alizadev-vehicletransfer:client:Confirmation:TransferVeh', function(idSeller, fullNameSeller, price, vehFullname, plate, model) local alert = lib.alertDialog({ header = string.format(Config.Locales['buyer_confirmation_header'], vehFullname, plate, fullNameSeller, price), centered = true, cancel = true }) if alert == 'confirm' then TriggerServerEvent('alizadev-vehicletransfer:server:VehicleTransfered', plate, idSeller, price, model) elseif alert == 'cancel' then QBCore.Functions.Notify(Config.Locales['contract_rejected'], 'error', 6000) TriggerServerEvent('alizadev-vehicletransfer:server:SendNotify', idSeller, Config.Locales['contract_rejected'], 'error', 6000) end end)