Skip to content

Commit

Permalink
chore: code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Frowmza committed Aug 29, 2024
1 parent 3e02f9d commit 556ce13
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 42 deletions.
21 changes: 4 additions & 17 deletions client/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
})
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 0 additions & 4 deletions server/finance.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
---@class InsertVehicleEntityRequest
---@field citizenId string
---@field model string
---@field plate string

---@class VehicleFinanceServer
---@field balance number
Expand All @@ -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
Expand Down
21 changes: 0 additions & 21 deletions server/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -298,7 +284,6 @@ RegisterNetEvent('qbx_vehicleshop:server:financeVehicle', function(downPayment,
insertVehicleEntityRequest = {
citizenId = cid,
model = vehicle,
plate = plate,
},
vehicleFinance = {
balance = balance,
Expand All @@ -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)

Expand Down Expand Up @@ -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

Expand All @@ -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)

Expand Down Expand Up @@ -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
Expand All @@ -407,7 +388,6 @@ RegisterNetEvent('qbx_vehicleshop:server:sellfinanceVehicle', function(downPayme
insertVehicleEntityRequest = {
citizenId = cid,
model = vehicle,
plate = plate,
},
vehicleFinance = {
balance = balance,
Expand All @@ -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
Expand Down

0 comments on commit 556ce13

Please sign in to comment.