Skip to content

Commit

Permalink
refactor(client): use lib.points
Browse files Browse the repository at this point in the history
  • Loading branch information
solareon authored Sep 24, 2024
1 parent 427bf98 commit accae86
Show file tree
Hide file tree
Showing 17 changed files with 545 additions and 1,869 deletions.
Binary file added .github/images/catalog.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .github/images/financemenu.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .github/images/financemenu2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .github/images/testdrive.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 4 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,16 @@
## Previews
**Catalog Main Menu**

![image](https://github.com/user-attachments/assets/1c0181dc-0a23-4b24-ac5a-cb36b2eb5bf3)
![image](.github/images/catalog.png)

**Configurable test drive times that automatically return the player**

![image](https://github.com/user-attachments/assets/ec513066-0e4f-401d-b3ba-178302682095)
![image](.github/images/testdrive.png)

**Financed Vehicles Menu Preview**

![image](https://github.com/user-attachments/assets/5dafcdcf-8299-4dc1-9770-04aee4c0e399)
![image](.github/images/financemenu.png)

**Make a payment or pay off vehicle in full**

![image](https://github.com/user-attachments/assets/17c5f71e-e64a-43b1-9a3c-4c1fa092e7ba)

# License notice
Due to unfortunate events, we had to remove the commit history of this repository. closed-source code was introduced of which the original copyright holder hadn't given anyone permission to share and was illegally obtained. This doesn't mean that the original contributors lost their copyright rights and still are copyright holders. This includes but is not limited to.
- legende11 | masonschafercodes | GhzGarage | Newtonzz | TheiLLeniumStudios | IdrisDose | r0adra93 | uShifty | Holidayy95 | erikmeyer08 | OlliePugh | roobr | gutsoo | Re1ease | TonybynMp4 | mjvanhaastert | Dwohakin | trclassic92 | ARSSANTO | TheiLLeniumStudios | BerkieBb | adweex | DannysRP | mNm-server | arsh939 | AbrahamMoody | buddizer | Z3rio | wanderrer | vosscat | LouieBandz514 | NoobySloth | merpindia | Belorico | Dhawgy | Sna-aaa | Brusein | PlanovskyJus | CptAllen | Evantually | amantu-qbit | MonkeyWhisper | Mobius1 | Demo4889 | DanteRedrum | steveski | DOSE-420 | nzkfc | izMystic | Aveeux
![image](.github/images/financemenu2.png)
141 changes: 90 additions & 51 deletions client/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ local VEHICLES = exports.qbx_core:GetVehiclesByName()
local VEHICLES_HASH = exports.qbx_core:GetVehiclesByHash()
local testDriveVeh = 0
local insideShop
local showroomPoints = {}

---@param data VehicleFinanceClient
local function financePayment(data)
Expand Down Expand Up @@ -401,6 +402,7 @@ local function endTestDrive()
LocalPlayer.state:set('isInTestDrive', false, true)
exports.qbx_core:Notify(locale('general.testdrive_complete'), 'success')
end

--- Starts the test drive timer based on time and shop
---@param time number
local function startTestDriveTimer(time)
Expand Down Expand Up @@ -454,7 +456,7 @@ end
local function createVehicleZone(shopName, coords, targetVehicle)
local shop = sharedConfig.shops[shopName]

lib.zones.box({
local boxZone = lib.zones.box({
coords = coords.xyz,
size = shop.zone.size,
rotation = coords.w,
Expand All @@ -479,6 +481,7 @@ local function createVehicleZone(shopName, coords, targetVehicle)
lib.hideTextUI()
end
})
return boxZone
end

--- Creates a shop
Expand All @@ -504,60 +507,111 @@ end
---@return number vehicleEntity
local function createShowroomVehicle(model, coords)
lib.requestModel(model, 10000)
local veh = CreateVehicle(model, coords.x, coords.y, coords.z, coords.w, false, false)
local veh = CreateVehicle(model, coords.x, coords.y, coords.z, coords.w, false, true)
SetModelAsNoLongerNeeded(model)
SetVehicleOnGroundProperly(veh)
SetEntityInvincible(veh, true)
SetVehicleDirtLevel(veh, 0.0)
SetVehicleDoorsLocked(veh, 3)
SetVehicleDoorsLocked(veh, 10)
FreezeEntityPosition(veh, true)
SetVehicleNumberPlateText(veh, 'BUY ME')

return veh
end

--- Initial function to set things up. Creating vehicleshops defined in the config and spawns the sellable vehicles
local shopVehs = {}
local function createShowroomVehiclePoint(data)
local vehPoint = lib.points.new({
coords = data.coords,
heading = data.coords.w,
distance = 300,
shopName = data.shopName,
vehiclePos = data.vehiclePos,
model = data.model,
veh = nil,
boxZone = nil
})

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

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)
end
self.veh = nil
self.boxZone = nil
end
return vehPoint
end

--- Initial function to set things up. Creating vehicleshops defined in the config and spawns the sellable vehicles
local function init()
CreateThread(function()
if sharedConfig.finance.enable then
lib.zones.box({
coords = sharedConfig.finance.zone,
size = vec3(2, 2, 4),
rotation = 0,
debug = config.debugPoly,
onEnter = function()
lib.showTextUI(locale('menus.keypress_showFinanceMenu'))
end,
inside = function()
if IsControlJustPressed(0, 38) then
showFinancedVehiclesMenu()
if config.useTarget then
exports.ox_target:createBoxZone({
coords = sharedConfig.finance.zone,
size = vec3(2, 2, 4),
rotation = 0,
debug = config.debugPoly,
options = {
{
name = 'vehicleshop:showFinanceMenu',
icon = 'fas fa-money-check',
label = locale('menus.finance_menu'),
onSelect = function()
showFinancedVehiclesMenu()
end
}
}
})
else
lib.zones.box({
coords = sharedConfig.finance.zone,
size = vec3(2, 2, 4),
rotation = 0,
debug = config.debugPoly,
onEnter = function()
lib.showTextUI(locale('menus.keypress_showFinanceMenu'))
end,
inside = function()
if IsControlJustPressed(0, 38) then
showFinancedVehiclesMenu()
end
end,
onExit = function()
lib.hideTextUI()
end
end,
onExit = function()
lib.hideTextUI()
end
})
})
end
end
end)

CreateThread(function()
for shopName, shop in pairs(sharedConfig.shops) do
createShop(shop.zone.shape, shopName)
showroomPoints[shopName] = {}

local showroomVehicles = sharedConfig.shops[shopName].showroomVehicles
for i = 1, #showroomVehicles do
local showroomVehicle = showroomVehicles[i]
local veh = createShowroomVehicle(showroomVehicle.vehicle, showroomVehicle.coords)

shopVehs[i] = veh

if config.useTarget then
createVehicleTarget(shopName, veh, i)
else
createVehicleZone(shopName, showroomVehicle.coords, i)
end
showroomPoints[shopName][i] = createShowroomVehiclePoint({
coords = showroomVehicle.coords,
shopName = shopName,
vehiclePos = i,
model = showroomVehicle.vehicle
})
end
end
end)
Expand All @@ -568,14 +622,6 @@ AddEventHandler('QBCore:Client:OnPlayerLoaded', function()
init()
end)

AddEventHandler('QBCore:Client:OnPlayerUnload', function()
for i = 1, #shopVehs do
DeleteEntity(shopVehs[i])
end

shopVehs = {}
end)

--- Starts the test drive. If vehicle parameter is not provided then the test drive will start with the closest vehicle to the player.
--- @param args table
RegisterNetEvent('qbx_vehicleshop:client:testDrive', function(args)
Expand Down Expand Up @@ -613,27 +659,20 @@ end)
RegisterNetEvent('qbx_vehicleshop:client:swapVehicle', function(data)
local shopName = data.closestShop
local dataTargetVehicle = sharedConfig.shops[shopName].showroomVehicles[data.targetVehicle]
if dataTargetVehicle.vehicle == data.toVehicle then return end
local vehPoint = showroomPoints[shopName][data.targetVehicle]

local closestVehicle = lib.getClosestVehicle(dataTargetVehicle.coords.xyz, 5, false)
if not closestVehicle then return end
if not vehPoint or dataTargetVehicle.vehicle == data.toVehicle then return end

if not IsModelInCdimage(data.toVehicle) then
lib.print.error(('Failed to find model for "%s". Vehicle might not be streamed?'):format(data.toVehicle))
return
end

DeleteEntity(closestVehicle)
while DoesEntityExist(closestVehicle) do
Wait(50)
end

local veh = createShowroomVehicle(data.toVehicle, dataTargetVehicle.coords)

dataTargetVehicle.vehicle = data.toVehicle

if config.useTarget then
createVehicleTarget(shopName, veh, data.targetVehicle)
vehPoint.model = data.toVehicle
if vehPoint.currentDistance <= vehPoint.distance then
vehPoint:onExit()
vehPoint:onEnter()
end
end)

Expand Down
3 changes: 2 additions & 1 deletion locales/cs.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@
"managed_finance_txt": "Financovani vozidla",
"submit_ID": "Server ID (#)",
"keypress_showFinanceMenu": "[E] Otvoriť ponuku Financie",
"keypress_vehicleViewMenu": "[E] Zobraziť vozidlo"
"keypress_vehicleViewMenu": "[E] Zobraziť vozidlo",
"target_showFinanceMenu": "Otvoriť ponuku Financie"
},
"general": {
"testdrive_timer": "Kolik zbyva do konce testovaci jizdy:",
Expand Down
3 changes: 2 additions & 1 deletion locales/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@
"managed_finance_txt": "Finance vehicle to Player",
"submit_ID": "Server ID (#)",
"keypress_showFinanceMenu": "[E] Menü Finanzen öffnen",
"keypress_vehicleViewMenu": "[E] Fahrzeug ansehen"
"keypress_vehicleViewMenu": "[E] Fahrzeug ansehen",
"target_showFinanceMenu": "Menü Finanzen öffnen"
},
"general": {
"testdrive_timer": "Test Drive Time Remaining:",
Expand Down
3 changes: 2 additions & 1 deletion locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@
"managed_finance_txt": "Finance vehicle to Player",
"submit_ID": "Server ID (#)",
"keypress_showFinanceMenu": "[E] Open Finance Menu",
"keypress_vehicleViewMenu": "[E] View Vehicle"
"keypress_vehicleViewMenu": "[E] View Vehicle",
"target_showFinanceMenu": "Open Finance Menu"
},
"general": {
"testdrive_timer": "Test Drive Time Remaining: ",
Expand Down
3 changes: 2 additions & 1 deletion locales/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@
"managed_finance_txt": "Financiar vehículo a jugador",
"submit_ID": "ID de servidor (#)",
"keypress_showFinanceMenu": "[E] Abrir Menú Finanzas",
"keypress_vehicleViewMenu": "[E] Ver vehículo"
"keypress_vehicleViewMenu": "[E] Ver vehículo",
"target_showFinanceMenu": "Abrir Menú Finanzas"
},
"general": {
"testdrive_timer": "Tiempo restante de prueba de manejo: ",
Expand Down
3 changes: 2 additions & 1 deletion locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@
"managed_finance_txt": "Faire financer ce véhicule",
"submit_ID": "ID du joueur (#)",
"keypress_showFinanceMenu": "[E] Ouvrir le menu Finance",
"keypress_vehicleViewMenu": "[E] Voir le véhicule"
"keypress_vehicleViewMenu": "[E] Voir le véhicule",
"target_showFinanceMenu": "Ouvrir le menu Finance"
},
"general": {
"testdrive_timer": "Temps restant: ",
Expand Down
3 changes: 2 additions & 1 deletion locales/hu.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@
"managed_finance_txt": "Kiválaszott jármű hitelezése a vásárlónak",
"submit_ID": "Idéglenes aktív személyiszám (#)",
"keypress_showFinanceMenu": "[E] Hitelezési menü megnyitása",
"keypress_vehicleViewMenu": "[E] Jármű megnézése"
"keypress_vehicleViewMenu": "[E] Jármű megnézése",
"target_showFinanceMenu": "Hitelezési menü megnyitása"
},
"general": {
"testdrive_timer": "Teszt vezetésből hátramaradt idő:",
Expand Down
3 changes: 2 additions & 1 deletion locales/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@
"managed_finance_txt": "Financier voertuig aan speler",
"submit_ID": "Server ID (#)",
"keypress_showFinanceMenu": "[E] Menu Financiën openen",
"keypress_vehicleViewMenu": "[E] Bekijk voertuig"
"keypress_vehicleViewMenu": "[E] Bekijk voertuig",
"target_showFinanceMenu": "Menu Financiën openen"
},
"general": {
"testdrive_timer": "Testrit tijd resterent:",
Expand Down
3 changes: 2 additions & 1 deletion locales/pt.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@
"managed_finance_txt": "Financiar veículo ao Jogador",
"submit_ID": "ID do Servidor (#)",
"keypress_showFinanceMenu": "[E] Abrir Menu de Financiamento",
"keypress_vehicleViewMenu": "[E] Ver Veículo"
"keypress_vehicleViewMenu": "[E] Ver Veículo",
"target_showFinanceMenu": "Abrir Menu de Financiamento"
},
"general": {
"testdrive_timer": "Tempo Restante de Test Drive: ",
Expand Down
3 changes: 2 additions & 1 deletion locales/ro.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@
"managed_finance_txt": "Vinde vehiculul in rate unui jucator",
"submit_ID": "ID-ul serverului (#)",
"keypress_showFinanceMenu": "[E] Deschideți meniul Finanțe",
"keypress_vehicleViewMenu": "[E] Vezi vehiculul"
"keypress_vehicleViewMenu": "[E] Vezi vehiculul",
"target_showFinanceMenu": "Deschideți meniul Finanțe"
},
"general": {
"testdrive_timer": "Timp ramas pentru testare:",
Expand Down
Loading

0 comments on commit accae86

Please sign in to comment.