From 556ce13e3d4087515b6dd0fe873babe12b374be9 Mon Sep 17 00:00:00 2001 From: Frowmza <66181451+Frowmza@users.noreply.github.com> Date: Thu, 29 Aug 2024 18:59:17 +0100 Subject: [PATCH] chore: code cleanup --- client/main.lua | 21 ++++----------------- server/finance.lua | 4 ---- server/main.lua | 21 --------------------- 3 files changed, 4 insertions(+), 42 deletions(-) diff --git a/client/main.lua b/client/main.lua index c2f36e2..848c393 100644 --- a/client/main.lua +++ b/client/main.lua @@ -97,8 +97,10 @@ local function showFinancedVehiclesMenu() for _, v in pairs(vehicles) do if v.balance and v.balance > 0 then + local plate = v.props.plate + plate = plate and plate:upper() + local vehicle = VEHICLES[v.modelName] - local plate = v.plate:upper() ownedVehicles[#ownedVehicles + 1] = { title = vehicle.name, description = locale('menus.veh_platetxt')..plate, @@ -619,7 +621,7 @@ RegisterNetEvent('qbx_vehicleshop:client:testDrive', function(args) local testDrive = sharedConfig.shops[insideShop].testDrive local plate = 'TEST'..lib.string.random('1111') local netId = lib.callback.await('qbx_vehicleshop:server:spawnVehicle', false, { - model = args.vehicle, + modelName = args.vehicle, coords = testDrive.spawn, plate = plate }) @@ -662,21 +664,6 @@ RegisterNetEvent('qbx_vehicleshop:client:swapVehicle', function(data) if config.useTarget then createVehicleTarget(shopName, veh, data.targetVehicle) end end) ---- Buys the selected vehicle ----@param vehicle number ----@param plate string -RegisterNetEvent('qbx_vehicleshop:client:buyShowroomVehicle', function(vehicle, plate, vehicleId) - local tempShop = insideShop -- temp hacky way of setting the shop because it changes after the callback has returned since you are outside the zone - local netId = lib.callback.await('qbx_vehicleshop:server:spawnVehicle', false, { - model = vehicle, - coords = config.shops[tempShop].vehicleSpawn, - plate = plate, - vehicleId = vehicleId - }) - local veh = NetToVeh(netId) - local props = lib.getVehicleProperties(veh) - props.plate = plate - TriggerServerEvent('qb-vehicletuning:server:SaveVehicleProps', props) end) local function confirmTrade(confirmationText) diff --git a/server/finance.lua b/server/finance.lua index 92af642..fe3462d 100644 --- a/server/finance.lua +++ b/server/finance.lua @@ -1,7 +1,6 @@ ---@class InsertVehicleEntityRequest ---@field citizenId string ---@field model string ----@field plate string ---@class VehicleFinanceServer ---@field balance number @@ -28,9 +27,6 @@ function finance.insertVehicleEntityWithFinance(request) local vehicleId = exports.qbx_vehicles:CreatePlayerVehicle({ model = insertVehicleEntityRequest.model, citizenid = insertVehicleEntityRequest.citizenId, - props = { - plate = insertVehicleEntityRequest.plate - } }) local vehicleFinance = request.vehicleFinance diff --git a/server/main.lua b/server/main.lua index 6115021..c035297 100644 --- a/server/main.lua +++ b/server/main.lua @@ -80,15 +80,6 @@ local function calculateNewFinance(paymentAmount, vehData) return qbx.math.round(newBalance), qbx.math.round(newPayment), newPaymentsLeft end -local function generateUniquePlate() - local plate - repeat - plate = qbx.generateRandomPlate('111AA11A') - Wait(0) - until not exports.qbx_vehicles:DoesPlayerVehiclePlateExist(plate) - return plate -end - -- Callbacks lib.callback.register('qbx_vehicleshop:server:GetVehiclesByName', function(source) local src = source @@ -251,13 +242,9 @@ RegisterNetEvent('qbx_vehicleshop:server:buyShowroomVehicle', function(vehicle) return exports.qbx_core:Notify(src, locale('error.notenoughmoney'), 'error') end - local plate = generateUniquePlate() local vehicleId = exports.qbx_vehicles:CreatePlayerVehicle({ model = vehicle, citizenid = player.PlayerData.citizenid, - props = { - plate = plate - } }) exports.qbx_core:Notify(src, locale('success.purchased'), 'success') TriggerClientEvent('qbx_vehicleshop:client:buyShowroomVehicle', src, vehicle, plate, vehicleId) @@ -289,7 +276,6 @@ RegisterNetEvent('qbx_vehicleshop:server:financeVehicle', function(downPayment, return exports.qbx_core:Notify(src, locale('error.notenoughmoney'), 'error') end - local plate = generateUniquePlate() local balance, vehPaymentAmount = calculateFinance(vehiclePrice, downPayment, paymentAmount) local cid = player.PlayerData.citizenid local timer = (config.finance.paymentInterval * 60) @@ -298,7 +284,6 @@ RegisterNetEvent('qbx_vehicleshop:server:financeVehicle', function(downPayment, insertVehicleEntityRequest = { citizenId = cid, model = vehicle, - plate = plate, }, vehicleFinance = { balance = balance, @@ -308,7 +293,6 @@ RegisterNetEvent('qbx_vehicleshop:server:financeVehicle', function(downPayment, } }) exports.qbx_core:Notify(src, locale('success.purchased'), 'success') - TriggerClientEvent('qbx_vehicleshop:client:buyShowroomVehicle', src, vehicle, plate, vehicleId) player.Functions.RemoveMoney(currencyType, downPayment, 'vehicle-bought-in-showroom') end) @@ -352,7 +336,6 @@ RegisterNetEvent('qbx_vehicleshop:server:sellShowroomVehicle', function(data, pl local vehicle = data local vehiclePrice = coreVehicles[vehicle].price local cid = target.PlayerData.citizenid - local plate = generateUniquePlate() if not sellShowroomVehicleTransact(src, target, vehiclePrice, vehiclePrice) then return end @@ -364,7 +347,6 @@ RegisterNetEvent('qbx_vehicleshop:server:sellShowroomVehicle', function(data, pl } }) - TriggerClientEvent('qbx_vehicleshop:client:buyShowroomVehicle', target.PlayerData.source, vehicle, plate, vehicleId) local shop = sharedConfig.shops[shopId] end) @@ -398,7 +380,6 @@ RegisterNetEvent('qbx_vehicleshop:server:sellfinanceVehicle', function(downPayme local cid = target.PlayerData.citizenid local timer = (config.finance.paymentInterval * 60) - local plate = generateUniquePlate() local balance, vehPaymentAmount = calculateFinance(vehiclePrice, downPayment, paymentAmount) if not sellShowroomVehicleTransact(src, target, vehiclePrice, downPayment) then return end @@ -407,7 +388,6 @@ RegisterNetEvent('qbx_vehicleshop:server:sellfinanceVehicle', function(downPayme insertVehicleEntityRequest = { citizenId = cid, model = vehicle, - plate = plate, }, vehicleFinance = { balance = balance, @@ -417,7 +397,6 @@ RegisterNetEvent('qbx_vehicleshop:server:sellfinanceVehicle', function(downPayme } }) - TriggerClientEvent('qbx_vehicleshop:client:buyShowroomVehicle', target.PlayerData.source, vehicle, plate, vehicleId) end) -- Check if payment is due