Skip to content

Commit

Permalink
Merge branch 'main' into chore/missing-stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
mafewtm authored Jan 9, 2025
2 parents a4da64b + d5a94a5 commit 9aeb4cf
Show file tree
Hide file tree
Showing 20 changed files with 195 additions and 591 deletions.
107 changes: 53 additions & 54 deletions client/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ local function financePayment(data)

if not dialog then return end

local paymentAmount = tonumber(dialog[1])
TriggerServerEvent('qbx_vehicleshop:server:financePayment', paymentAmount, data.vehId)
local amount = tonumber(dialog[1])
TriggerServerEvent('qbx_vehicleshop:server:financePayment', amount, data.vehId)
end

local function confirmationCheck()
Expand All @@ -38,12 +38,12 @@ end

---@param data VehicleFinanceClient
local function showVehicleFinanceMenu(data)
local vehLabel = ('%s %s'):format(data.brand, data.name)
local vehFinance = {
local label = ('%s %s'):format(data.brand, data.name)
local options = {
{
title = 'Finance Information',
icon = 'circle-info',
description = ('Name: %s\nPlate: %s\nRemaining Balance: $%s\nRecurring Payment Amount: $%s\nPayments Left: %s'):format(vehLabel, data.vehiclePlate, lib.math.groupdigits(data.balance), lib.math.groupdigits(data.paymentAmount), data.paymentsLeft),
description = ('Name: %s\nPlate: %s\nRemaining Balance: $%s\nRecurring Payment Amount: $%s\nPayments Left: %s'):format(label, data.vehiclePlate, lib.math.groupdigits(data.balance), lib.math.groupdigits(data.paymentAmount), data.paymentsLeft),
readOnly = true,
},
{
Expand All @@ -70,7 +70,7 @@ local function showVehicleFinanceMenu(data)
id = 'vehicleFinance',
title = locale('menus.financed_header'),
menu = 'ownedVehicles',
options = vehFinance
options = options
})

lib.showContext('vehicleFinance')
Expand All @@ -79,7 +79,7 @@ end
--- Gets the owned vehicles based on financing then opens a menu
local function showFinancedVehiclesMenu()
local vehicles = lib.callback.await('qbx_vehicleshop:server:GetFinancedVehicles')
local ownedVehicles = {}
local options = {}

if not vehicles or #vehicles == 0 then
return exports.qbx_core:Notify(locale('error.nofinanced'), 'error')
Expand All @@ -91,7 +91,7 @@ local function showFinancedVehiclesMenu()

plate = plate and plate:upper()

ownedVehicles[#ownedVehicles + 1] = {
options[#options + 1] = {
title = vehicle.name,
description = locale('menus.veh_platetxt')..plate,
icon = 'fa-solid fa-car-side',
Expand All @@ -110,14 +110,14 @@ local function showFinancedVehiclesMenu()
}
end

if #ownedVehicles == 0 then
if #options == 0 then
return exports.qbx_core:Notify(locale('error.nofinanced'), 'error')
end

lib.registerContext({
id = 'ownedVehicles',
title = locale('menus.owned_vehicles_header'),
options = ownedVehicles
options = options
})

lib.showContext('ownedVehicles')
Expand Down Expand Up @@ -180,8 +180,8 @@ end
---@param category string
---@param targetVehicle number
local function openVehCatsMenu(category, targetVehicle)

local categoryMenu = {}

for i = 1, vehiclesMenu.count do
local vehicle = vehiclesMenu.vehicles[i]
if vehicle.category == category and vehicle.shopType == insideShop then
Expand All @@ -202,8 +202,8 @@ local function openVehCatsMenu(category, targetVehicle)
end

--- Opens a menu with list of vehicle categories
---@param args {targetVehicle: integer}
local function openVehicleCategoryMenu(args)
---@param targetVehicle integer
local function openVehicleCategoryMenu(targetVehicle)
local categoryMenu = {}
local sortedCategories = {}
local categories = sharedConfig.shops[insideShop].categories
Expand All @@ -216,15 +216,15 @@ local function openVehicleCategoryMenu(args)
end

table.sort(sortedCategories, function(a, b)
return string.upper(a.label) < string.upper(b.label)
return a.label:upper() < b.label:upper()
end)

for i = 1, #sortedCategories do
categoryMenu[#categoryMenu + 1] = {
title = sortedCategories[i].label,
arrow = true,
onSelect = function()
openVehCatsMenu(sortedCategories[i].category, args.targetVehicle)
openVehCatsMenu(sortedCategories[i].category, targetVehicle)
end
}
end
Expand Down Expand Up @@ -262,11 +262,11 @@ local function openCustomFinance(targetVehicle)

local downPayment = tonumber(dialog[1])
local paymentAmount = tonumber(dialog[2])
local playerid = tonumber(dialog[3])
local playerId = tonumber(dialog[3])

if not downPayment or not paymentAmount or not playerid then return end
if not downPayment or not paymentAmount or not playerId then return end

TriggerServerEvent('qbx_vehicleshop:server:sellfinanceVehicle', downPayment, paymentAmount, vehicle, playerid)
TriggerServerEvent('qbx_vehicleshop:server:sellfinanceVehicle', downPayment, paymentAmount, vehicle, playerId)
end

---prompt client for playerId of another player
Expand Down Expand Up @@ -314,10 +314,9 @@ local function openVehicleSellMenu(targetVehicle)
local swapOption = {
title = locale('menus.swap_header'),
description = locale('menus.swap_txt'),
onSelect = openVehicleCategoryMenu,
args = {
targetVehicle = targetVehicle
},
onSelect = function()
openVehicleCategoryMenu(targetVehicle)
end,
arrow = true
}

Expand All @@ -326,21 +325,19 @@ local function openVehicleSellMenu(targetVehicle)
options[#options + 1] = {
title = locale('menus.test_header'),
description = locale('menus.freeuse_test_txt'),
serverEvent = 'qbx_vehicleshop:server:testDrive',
args = {
vehicle = vehicle
}
onSelect = function()
TriggerServerEvent('qbx_vehicleshop:server:testDrive', vehicle)
end,
}
end

if sharedConfig.enableFreeUseBuy then
options[#options + 1] = {
title = locale('menus.freeuse_buy_header'),
description = locale('menus.freeuse_buy_txt'),
serverEvent = 'qbx_vehicleshop:server:buyShowroomVehicle',
args = {
buyVehicle = vehicle
}
onSelect = function()
TriggerServerEvent('qbx_vehicleshop:server:buyShowroomVehicle', vehicle)
end,
}
end

Expand Down Expand Up @@ -404,7 +401,7 @@ local function createVehicleTarget(shopName, entity, targetVehicle)

exports.ox_target:addLocalEntity(entity, {
{
name = 'vehicleshop:showVehicleOptions',
name = 'showVehicleOptions',
icon = 'fas fa-car',
label = locale('general.vehinteraction'),
distance = shop.zone.targetDistance,
Expand Down Expand Up @@ -494,30 +491,32 @@ local function createShowroomVehiclePoint(data)
vehiclePos = data.vehiclePos,
model = data.model,
veh = nil,
boxZone = nil
})
boxZone = nil,
onEnter = function(self)
self.veh = createShowroomVehicle(self.model, vec4(self.coords.x, self.coords.y, self.coords.z, self.heading))

function vehPoint:onEnter()
self.veh = createShowroomVehicle(self.model, vec4(self.coords.x, self.coords.y, self.coords.z, self.heading))
if config.useTarget then
createVehicleTarget(self.shopName, self.veh, self.vehiclePos)
else
self.boxZone = createVehicleZone(self.shopName, self.coords, self.vehiclePos)
end
end
if config.useTarget then
createVehicleTarget(self.shopName, self.veh, self.vehiclePos)
else
self.boxZone = createVehicleZone(self.shopName, self.coords, self.vehiclePos)
end
end,
onExit = function(self)
if config.useTarget then
exports.ox_target:removeLocalEntity(self.veh, 'showVehicleOptions')
else
self.boxZone:remove()
end

function vehPoint:onExit()
if config.useTarget then
exports.ox_target:removeLocalEntity(self.veh, 'vehicleshop:showVehicleOptions')
else
self.boxZone:remove()
end
if DoesEntityExist(self.veh) then
DeleteEntity(self.veh)
if DoesEntityExist(self.veh) then
DeleteEntity(self.veh)
end

self.veh = nil
self.boxZone = nil
end
self.veh = nil
self.boxZone = nil
end
})

return vehPoint
end

Expand Down Expand Up @@ -643,7 +642,7 @@ CreateThread(function()
debug = config.debugPoly,
options = {
{
name = 'vehicleshop:showFinanceMenu',
name = 'showFinanceMenu',
icon = 'fas fa-money-check',
label = locale('menus.finance_menu'),
onSelect = function()
Expand Down Expand Up @@ -703,4 +702,4 @@ CreateThread(function()
})
end
end
end)
end)
7 changes: 3 additions & 4 deletions client/vehicles.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ local vehicles = {}
local blocklist = {}
local VEHICLES = exports.qbx_core:GetVehiclesByName()
local sharedConfig = require 'config.shared'.vehicles
local groupdigits = lib.math.groupdigits
local count = 0

local function insertVehicle(vehicleData, shopType)
Expand All @@ -12,7 +11,7 @@ local function insertVehicle(vehicleData, shopType)
category = vehicleData.category,

title = ('%s %s'):format(vehicleData.brand, vehicleData.name),
description = ('%s%s'):format(locale('menus.veh_price'), groupdigits(vehicleData.price)),
description = ('%s%s'):format(locale('menus.veh_price'), lib.math.groupdigits(vehicleData.price)),
serverEvent = 'qbx_vehicleshop:server:swapVehicle',
args = {
toVehicle = vehicleData.model,
Expand Down Expand Up @@ -44,8 +43,8 @@ for k, vehicle in pairs(VEHICLES) do
end

table.sort(vehicles, function(a, b)
local _, aName = string.strsplit(' ', string.upper(a.title), 2)
local _, bName = string.strsplit(' ', string.upper(b.title), 2)
local _, aName = a.title:upper():strsplit(' ', 2)
local _, bName = b.title:upper():strsplit(' ', 2)

return aName < bName
end)
Expand Down
Loading

0 comments on commit 9aeb4cf

Please sign in to comment.