Skip to content

Commit

Permalink
refactor: config and event names
Browse files Browse the repository at this point in the history
* refactor: config and event names

* Update README.md

* fix: config string readability
  • Loading branch information
mafewtm authored Nov 28, 2023
1 parent 5722dcb commit 6b7ab00
Show file tree
Hide file tree
Showing 4 changed files with 242 additions and 180 deletions.
9 changes: 0 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,6 @@

![image](https://user-images.githubusercontent.com/57848836/138771627-faed7fcb-73c8-4b77-a33f-fffbb738ab03.png)

### Dependencies:

**[PolyZone](https://github.com/qbcore-framework/PolyZone)**

* You need to create new PolyZones if you want to create a new dealership or move default locations to another area. After you create the new PolyZones, add them to the config.shops > [Shape]

* Here's a Wiki on how to create new PolyZone:
https://github.com/mkafrin/PolyZone/wiki/Using-the-creation-script

# 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
65 changes: 35 additions & 30 deletions client/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ local function showVehicleFinanceMenu(data)
}

lib.registerContext({
id = 'vehFinance',
id = 'vehicleFinance',
title = Lang:t('menus.financed_header'),
menu = 'owned_vehicles',
menu = 'ownedVehicles',
options = vehFinance
})

lib.showContext('vehFinance')
lib.showContext('vehicleFinance')
end

--- Gets the owned vehicles based on financing then opens a menu
Expand Down Expand Up @@ -99,15 +99,15 @@ local function showFinancedVehiclesMenu()
end

lib.registerContext({
id = 'owned_vehicles',
id = 'ownedVehicles',
title = Lang:t('menus.owned_vehicles_header'),
options = ownedVehicles
})
lib.showContext('owned_vehicles')
lib.showContext('ownedVehicles')
end

lib.registerContext({
id = 'fin_header_menu',
id = 'financeHeaderMenu',
title = Lang:t('menus.financed_header'),
options = {
{
Expand All @@ -126,21 +126,24 @@ end)
---@param closestVehicle integer
---@return string
local function getVehName(closestVehicle)
return VEHICLES[config.shops[insideShop].showroomVehicles[closestVehicle].chosenVehicle].name
local chosenVehicle = config.shops[insideShop].showroomVehicles[closestVehicle].chosenVehicle
return VEHICLES[chosenVehicle].name
end

--- Fetches the price of a vehicle from QB Shared then it formats it into a text
---@param closestVehicle integer
---@return string
local function getVehPrice(closestVehicle)
return CommaValue(VEHICLES[config.shops[insideShop].showroomVehicles[closestVehicle].chosenVehicle].price)
local chosenVehicle = config.shops[insideShop].showroomVehicles[closestVehicle].chosenVehicle
return CommaValue(VEHICLES[chosenVehicle].price)
end

--- Fetches the brand of a vehicle from QB Shared
---@param closestVehicle integer
---@return string
local function getVehBrand(closestVehicle)
return VEHICLES[config.shops[insideShop].showroomVehicles[closestVehicle].chosenVehicle].brand
local chosenVehicle = config.shops[insideShop].showroomVehicles[closestVehicle].chosenVehicle
return VEHICLES[chosenVehicle].brand
end

--- based on which vehicleshop player is in
Expand Down Expand Up @@ -224,13 +227,13 @@ local function openVehCatsMenu(category)
end

lib.registerContext({
id = 'open_veh_cats',
id = 'openVehCats',
title = Lang:t('menus.categories_header'),
menu = 'vehicleCategories',
options = vehMenu
})

lib.showContext('open_veh_cats')
lib.showContext('openVehCats')
end

--- Opens a menu with list of vehicle categories
Expand All @@ -249,7 +252,7 @@ local function openVehicleCategoryMenu()
lib.registerContext({
id = 'vehicleCategories',
title = Lang:t('menus.categories_header'),
menu = 'veh_menu',
menu = 'vehicleMenu',
options = categoryMenu
})

Expand Down Expand Up @@ -322,6 +325,7 @@ end
local function openVehicleSellMenu()
local closestVehicle = getClosestShowroomVehicle()
local options
local chosenVehicle = config.shops[insideShop].showroomVehicles[closestVehicle].chosenVehicle
local swapOption = {
title = Lang:t('menus.swap_header'),
description = Lang:t('menus.swap_txt'),
Expand All @@ -333,9 +337,9 @@ local function openVehicleSellMenu()
{
title = Lang:t('menus.test_header'),
description = Lang:t('menus.freeuse_test_txt'),
event = 'qbx_vehicleshop:client:TestDrive',
event = 'qbx_vehicleshop:client:testDrive',
args = {
vehicle = config.shops[insideShop].showroomVehicles[closestVehicle].chosenVehicle
vehicle = chosenVehicle
}
}
}
Expand All @@ -346,7 +350,7 @@ local function openVehicleSellMenu()
description = Lang:t('menus.freeuse_buy_txt'),
serverEvent = 'qbx_vehicleshop:server:buyShowroomVehicle',
args = {
buyVehicle = config.shops[insideShop].showroomVehicles[closestVehicle].chosenVehicle
buyVehicle = chosenVehicle
}
}
end
Expand All @@ -356,7 +360,7 @@ local function openVehicleSellMenu()
title = Lang:t('menus.finance_header'),
description = Lang:t('menus.freeuse_finance_txt'),
onSelect = function()
openFinance(closestVehicle, config.shops[insideShop].showroomVehicles[closestVehicle].chosenVehicle)
openFinance(closestVehicle, chosenVehicle)
end
}
end
Expand All @@ -368,14 +372,14 @@ local function openVehicleSellMenu()
title = Lang:t('menus.test_header'),
description = Lang:t('menus.managed_test_txt'),
onSelect = function()
startTestDrive(config.shops[insideShop].showroomVehicles[closestVehicle].chosenVehicle)
startTestDrive(chosenVehicle)
end,
},
{
title = Lang:t('menus.managed_sell_header'),
description = Lang:t('menus.managed_sell_txt'),
onSelect = function()
sellVehicle(config.shops[insideShop].showroomVehicles[closestVehicle].chosenVehicle)
sellVehicle(chosenVehicle)
end,
}
}
Expand All @@ -394,11 +398,11 @@ local function openVehicleSellMenu()
end

lib.registerContext({
id = 'veh_menu',
id = 'vehicleMenu',
title = getVehBrand(closestVehicle):upper()..' '..getVehName(closestVehicle):upper()..' - $'..getVehPrice(closestVehicle),
options = options
})
lib.showContext('veh_menu')
lib.showContext('vehicleMenu')
end

--- Starts the test drive timer based on time and shop
Expand All @@ -417,7 +421,8 @@ local function startTestDriveTimer(time, shop)
TriggerServerEvent('qbx_vehicleshop:server:deleteVehicle', testDriveVeh)
testDriveVeh = 0
inTestDrive = false
SetEntityCoords(cache.ped, config.shops[shop].testDriveReturnLocation.x, config.shops[shop].testDriveReturnLocation.y, config.shops[shop].testDriveReturnLocation.z, false, false, false, false)
local returnCoords = config.shops[shop].testDrive.returnCoords
SetEntityCoords(cache.ped, returnCoords.x, returnCoords.y, returnCoords.z, false, false, false, false)
exports.qbx_core:Notify(Lang:t('general.testdrive_complete'), 'success')
end
DrawText2D(Lang:t('general.testdrive_timer')..math.ceil(time - secondsLeft / 1000), vec2(1.0, 0.93))
Expand Down Expand Up @@ -455,12 +460,12 @@ local function createVehicleZone(shopName, coords)
debug = config.debugPoly,
onEnter = function()
local job = config.shops[insideShop].job
if QBX.PlayerData.job.name ~= job then return end
if job and QBX.PlayerData.job.name ~= job then return end
lib.showTextUI(Lang:t('menus.keypress_vehicleViewMenu'))
end,
inside = function()
local job = config.shops[insideShop].job
if not IsControlJustPressed(0, 38) or not QBX.PlayerData or not QBX.PlayerData.job or (QBX.PlayerData.job.name ~= job and job ~= 'none') then return end
if not IsControlJustPressed(0, 38) or job and QBX.PlayerData.job.name ~= job then return end
openVehicleSellMenu()
end,
onExit = function()
Expand Down Expand Up @@ -524,7 +529,7 @@ local function init()
end,
inside = function()
if IsControlJustPressed(0, 38) then
lib.showContext('fin_header_menu')
lib.showContext('financeHeaderMenu')
end
end,
onExit = function()
Expand Down Expand Up @@ -567,7 +572,7 @@ 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)
RegisterNetEvent('qbx_vehicleshop:client:testDrive', function(args)
if inTestDrive then
exports.qbx_core:Notify(Lang:t('error.testdrive_alreadyin'), 'error')
return
Expand All @@ -576,11 +581,11 @@ RegisterNetEvent('qbx_vehicleshop:client:TestDrive', function(args)
if not args then return end

inTestDrive = true
local tempShop = insideShop
local netId = lib.callback.await('qbx_vehicleshop:server:spawnVehicle', false, args.vehicle, config.shops[tempShop].testDriveSpawn, 'TEST '..RandomNumber(3))
local testDrive = config.shops[insideShop].testDrive
local netId = lib.callback.await('qbx_vehicleshop:server:spawnVehicle', false, args.vehicle, testDrive.spawnCoords, 'TEST '..RandomNumber(3))
testDriveVeh = netId
exports.qbx_core:Notify(Lang:t('general.testdrive_timenoti'), config.shops[tempShop].testDriveTimeLimit, 'inform')
startTestDriveTimer(config.shops[tempShop].testDriveTimeLimit * 60, tempShop)
exports.qbx_core:Notify(Lang:t('general.testdrive_timenoti'), testDrive.limit, 'inform')
startTestDriveTimer(testDrive.limit * 60, insideShop)
end)

--- Swaps the chosen vehicle with another one
Expand All @@ -600,7 +605,7 @@ RegisterNetEvent('qbx_vehicleshop:client:swapVehicle', function(data)

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

config.shops[shopName].showroomVehicles[data.ClosestVehicle].chosenVehicle = data.toVehicle
dataClosestVehicle.chosenVehicle = data.toVehicle

if config.useTarget then createVehicleTarget(shopName, veh) end
end)
Expand Down
Loading

0 comments on commit 6b7ab00

Please sign in to comment.