Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: config coords all vec4s. Some minor refactors #42

Merged
merged 1 commit into from
Apr 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 42 additions & 40 deletions client/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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] = {
Expand Down Expand Up @@ -284,46 +293,46 @@ 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,
debug = config.debugPoly,
})
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,
},
Expand All @@ -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,
},
Expand All @@ -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
Expand All @@ -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)
45 changes: 23 additions & 22 deletions config/shared.lua
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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<string, GarageConfig>
---@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<string, GarageConfig>
garages = {
-- Public Garages
motelgarage = {
label = 'Motel Parking',
Expand Down Expand Up @@ -114,15 +115,15 @@ 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,
vehicle = VehicleType.CAR,
},
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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down