From a05928571a374df14177e732a9cbc3904a8266a2 Mon Sep 17 00:00:00 2001 From: Manason Date: Sun, 28 Apr 2024 08:27:59 -0700 Subject: [PATCH] fix: config coords all vec4s. Some minor refactors --- client/main.lua | 82 ++++++++++++++++++++++++----------------------- config/shared.lua | 45 +++++++++++++------------- 2 files changed, 65 insertions(+), 62 deletions(-) diff --git a/client/main.lua b/client/main.lua index fef2927..e7cd12a 100644 --- a/client/main.lua +++ b/client/main.lua @@ -43,7 +43,7 @@ local VehicleCategory = { ---@param category VehicleType ---@param vehicle number ---@return boolean -local function checkVehicleClass(category, vehicle) +local function isOfType(category, vehicle) local classSet = {} for _, class in pairs(VehicleCategory[category]) do @@ -97,6 +97,14 @@ local function checkPlayers(vehicle) DeleteVehicle(vehicle) end +local function takeOutDepot(data) + if data.vehicle.depotprice ~= 0 then + TriggerServerEvent('qb-garage:server:PayDepotPrice', data) + else + TriggerEvent('qb-garages:client:takeOutGarage', data) + end +end + local function displayVehicleInfo(vehicle, garageName, garageInfo) local engine = qbx.math.round(vehicle.engine / 10) local body = qbx.math.round(vehicle.body / 10) @@ -142,13 +150,14 @@ local function displayVehicleInfo(vehicle, garageName, garageInfo) title = 'Take out', icon = 'fa-truck-ramp-box', description = ('$%s'):format(lib.math.groupdigits(vehicle.depotprice)), - event = 'qb-garages:client:TakeOutDepot', arrow = true, - args = { - vehicle = vehicle, - garageInfo = garageInfo, - garageName = garageName, - }, + onSelect = function() + takeOutDepot({ + vehicle = vehicle, + garageInfo = garageInfo, + garageName = garageName + }) + end, } else options[#options + 1] = { @@ -284,28 +293,28 @@ local function parkVehicle(vehicle, garageName, garageInfo) end end -local function createZones(garageName, garageInfo) +local function createZones(garageName, garage) CreateThread(function() if not config.useTarget then lib.zones.box({ - coords = garageInfo.coords.xyz, - size = garageInfo.size, - rotation = garageInfo.coords.w, + coords = garage.coords.xyz, + size = garage.size, + rotation = garage.coords.w, onEnter = function() - lib.showTextUI((garageInfo.type == GarageType.DEPOT and 'E - Open Impound') or (cache.vehicle and 'E - Store Vehicle') or 'E - Open Garage') + lib.showTextUI((garage.type == GarageType.DEPOT and 'E - Open Impound') or (cache.vehicle and 'E - Store Vehicle') or 'E - Open Garage') end, onExit = function() lib.hideTextUI() end, inside = function() if IsControlJustReleased(0, 38) then - if cache.vehicle and garageInfo.type ~= GarageType.DEPOT then - if not checkVehicleClass(garageInfo.vehicle, cache.vehicle) then + if cache.vehicle and garage.type ~= GarageType.DEPOT then + if not isOfType(garage.vehicle, cache.vehicle) then return exports.qbx_core:Notify('You can\'t park this vehicle here...', 'error') end - parkVehicle(cache.vehicle, garageName, garageInfo) + parkVehicle(cache.vehicle, garageName, garage) else - openGarageMenu(garageName, garageInfo) + openGarageMenu(garageName, garage) end end end, @@ -313,17 +322,17 @@ local function createZones(garageName, garageInfo) }) else exports.ox_target:addBoxZone({ - coords = garageInfo.coords.xyz, - size = garageInfo.size, - rotation = garageInfo.coords.w, + coords = garage.coords.xyz, + size = garage.size, + rotation = garage.coords.w, debug = config.debugPoly, options = { { name = 'openGarage', - label = garageInfo.type == GarageType.DEPOT and 'Open Impound' or 'Open Garage', + label = garage.type == GarageType.DEPOT and 'Open Impound' or 'Open Garage', icon = 'fas fa-car', onSelect = function() - openGarageMenu(garageName, garageInfo) + openGarageMenu(garageName, garage) end, distance = 10, }, @@ -332,13 +341,13 @@ local function createZones(garageName, garageInfo) label = 'Store Vehicle', icon = 'fas fa-square-parking', canInteract = function() - return garageInfo.type ~= GarageType.DEPOT and cache.vehicle + return garage.type ~= GarageType.DEPOT and cache.vehicle end, onSelect = function() - if not checkVehicleClass(garageInfo.vehicle, cache.vehicle) then + if not isOfType(garage.vehicle, cache.vehicle) then return exports.qbx_core:Notify('You can\'t park this vehicle here...', 'error') end - parkVehicle(cache.vehicle, garageName, garageInfo) + parkVehicle(cache.vehicle, garageName, garage) end, distance = 10, }, @@ -361,15 +370,16 @@ local function createBlips(garageInfo) end local function createGarages() - for name, info in pairs(sharedConfig.garages) do - if info.showBlip or info.showBlip == nil then - createBlips(info) + for name, garage in pairs(sharedConfig.garages) do + -- default to showing blips if showBlip is not set + if garage.showBlip or garage.showBlip == nil then + createBlips(garage) end - if info.type == GarageType.JOB and (QBX.PlayerData.job.name == info.job or QBX.PlayerData.job.type == info.job) or - info.type == GarageType.GANG and QBX.PlayerData.gang.name == info.job or - info.type ~= GarageType.JOB and info.type ~= GarageType.GANG then - createZones(name, info) + if garage.type == GarageType.JOB and (QBX.PlayerData.job.name == garage.job or QBX.PlayerData.job.type == garage.job) or + garage.type == GarageType.GANG and QBX.PlayerData.gang.name == garage.job or + garage.type ~= GarageType.JOB and garage.type ~= GarageType.GANG then + createZones(name, garage) end end end @@ -381,12 +391,4 @@ end) AddEventHandler('onResourceStart', function(resource) if resource ~= cache.resource then return end createGarages() -end) - -RegisterNetEvent('qb-garages:client:TakeOutDepot', function(data) - if data.vehicle.depotprice ~= 0 then - TriggerServerEvent('qb-garage:server:PayDepotPrice', data) - else - TriggerEvent('qb-garages:client:takeOutGarage', data) - end -end) +end) \ No newline at end of file diff --git a/config/shared.lua b/config/shared.lua index 2f3de3d..de2b106 100644 --- a/config/shared.lua +++ b/config/shared.lua @@ -1,3 +1,5 @@ +require 'shared.types' + return { takeOut = { warpInVehicle = false, -- If false, player will no longer warp into vehicle upon taking the vehicle out. @@ -6,23 +8,22 @@ return { }, houseGarages = {}, -- Dont touch - garages = { - ---@class GarageConfig - ---@field label string -- Label for the garage - ---@field coords vector4 -- Coordinates for the garage - ---@field size vector3 -- Size of the garage - ---@field spawn vector4 -- Coordinates where the vehicle will spawn - ---@field showBlip boolean -- Enable or disable the blip - ---@field blipName string -- Name of the blip - ---@field blipSprite number -- Sprite for the blip - ---@field blipColor number -- Color for the blip - ---@field type GarageType -- Type of garage - ---@field vehicle VehicleType -- Vehicle type - ---@field job string -- Job / Gang name - - ---@type table + ---@class GarageConfig + ---@field label string -- Label for the garage + ---@field coords vector4 -- Coordinates for the garage + ---@field size vector3 -- Size of the garage + ---@field spawn vector4 -- Coordinates where the vehicle will spawn + ---@field showBlip? boolean -- Enable or disable the blip. Defaults to true + ---@field blipName? string -- Name of the blip. Defaults to garage label. + ---@field blipSprite? number -- Sprite for the blip. Defaults to 357 + ---@field blipColor? number -- Color for the blip. Defaults to 3. + ---@field type GarageType -- Type of garage + ---@field vehicle VehicleType -- Vehicle type + ---@field job? string -- Job / Gang name that can access the garage. + ---@type table + garages = { -- Public Garages motelgarage = { label = 'Motel Parking', @@ -114,7 +115,7 @@ return { }, haanparking = { label = 'Bell Farms Parking', - coords = vec3(78.34, 6418.74, 31.28), + coords = vec4(78.34, 6418.74, 31.28, 0), size = vec3(10, 10, 10), spawn = vec4(70.71, 6425.16, 30.92, 68.5), type = GarageType.PUBLIC, @@ -122,7 +123,7 @@ return { }, dumbogarage = { label = 'Dumbo Private Parking', - coords = vec3(157.26, -3240.00, 7.00), + coords = vec4(157.26, -3240.00, 7.00, 0), size = vec3(10, 10, 10), spawn = vec4(165.32, -3236.10, 5.93, 268.5), type = GarageType.PUBLIC, @@ -200,7 +201,7 @@ return { -- Job Garages police = { label = 'Police', - coords = vec3(454.6, -1017.4, 28.4), + coords = vec4(454.6, -1017.4, 28.4, 0), size = vec3(10, 10, 10), spawn = vec4(438.4, -1018.3, 27.7, 90.0), showBlip = false, @@ -214,7 +215,7 @@ return { -- Gang Garages ballas = { label = 'Ballas', - coords = vec3(98.50, -1954.49, 20.84), + coords = vec4(98.50, -1954.49, 20.84, 0), size = vec3(10, 10, 10), spawn = vec4(98.50, -1954.49, 20.75, 335.73), showBlip = false, @@ -226,7 +227,7 @@ return { }, families = { label = 'La Familia', - coords = vec3(-811.65, 187.49, 72.48), + coords = vec4(-811.65, 187.49, 72.48, 0), size = vec3(10, 10, 10), spawn = vec4(-818.43, 184.97, 72.28, 107.85), showBlip = false, @@ -238,7 +239,7 @@ return { }, lostmc = { label = 'Lost MC', - coords = vec3(957.25, -129.63, 74.39), + coords = vec4(957.25, -129.63, 74.39, 0), size = vec3(10, 10, 10), spawn = vec4(957.25, -129.63, 74.39, 199.21), showBlip = false, @@ -250,7 +251,7 @@ return { }, cartel = { label = 'Cartel', - coords = vec3(1407.18, 1118.04, 114.84), + coords = vec4(1407.18, 1118.04, 114.84, 0), size = vec3(10, 10, 10), spawn = vec4(1407.18, 1118.04, 114.84, 88.34), showBlip = false,