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(vehicles): use zones instead of targets #140

Merged
merged 1 commit into from
Sep 8, 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
106 changes: 50 additions & 56 deletions client/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -148,38 +148,35 @@ local function createGarage(job, garages)
for i = 1, #garages do
local garage = garages[i]

exports.ox_target:addSphereZone({
lib.zones.sphere({
coords = garage.coords,
radius = garage.radius,
debug = config.debugPoly,
options = {
{
name = ('%s-Garage'):format(job),
icon = 'fa-solid fa-warehouse',
label = locale('targets.garage'),
canInteract = function()
return not cache.vehicle and QBX.PlayerData.job.onduty
end,
onSelect = function()
vehicles.openGarage(garage)
end,
groups = garage.groups,
distance = 1.5,
},
{
name = ('%s-GarageStore'):format(job),
icon = 'fa-solid fa-square-parking',
label = locale('targets.store_vehicle'),
canInteract = function()
return cache.vehicle and QBX.PlayerData.job.onduty
end,
onSelect = function()
onEnter = function()
local hasGroup = exports.qbx_core:HasGroup(garage.groups)

if not hasGroup or not QBX.PlayerData.job.onduty then return end

lib.showTextUI(cache.vehicle and locale('vehicles.store_vehicle') or locale('vehicles.open_garage'))
end,
inside = function()
local hasGroup = exports.qbx_core:HasGroup(garage.groups)

if not hasGroup or not QBX.PlayerData.job.onduty then return end

if IsControlJustReleased(0, 38) then
if cache.vehicle then
vehicles.store(cache.vehicle)
end,
groups = garage.groups,
distance = 1.5,
},
}
else
vehicles.openHelipad(garage)
end

lib.hideTextUI()
end
end,
onExit = function()
lib.hideTextUI()
end,
})
end
end
Expand All @@ -192,38 +189,35 @@ local function createHelipad(job, helipads)
for i = 1, #helipads do
local helipad = helipads[i]

exports.ox_target:addSphereZone({
lib.zones.sphere({
coords = helipad.coords,
radius = helipad.radius,
debug = config.debugPoly,
options = {
{
name = ('%s-Helipad'):format(job),
icon = 'fa-solid fa-helicopter-symbol',
label = locale('targets.helipad'),
canInteract = function()
return not cache.vehicle and QBX.PlayerData.job.onduty
end,
onSelect = function()
vehicles.openHelipad(helipad)
end,
groups = helipad.groups,
distance = 1.5,
},
{
name = ('%s-HelipadStore'):format(job),
icon = 'fa-solid fa-square-parking',
label = locale('targets.store_helicopter'),
canInteract = function()
return cache.vehicle and QBX.PlayerData.job.onduty
end,
onSelect = function()
onEnter = function()
local hasGroup = exports.qbx_core:HasGroup(helipad.groups)

if not hasGroup or not QBX.PlayerData.job.onduty then return end

lib.showTextUI(cache.vehicle and locale('vehicles.store_helicopter') or locale('vehicles.open_helipad'))
end,
inside = function()
local hasGroup = exports.qbx_core:HasGroup(helipad.groups)

if not hasGroup or not QBX.PlayerData.job.onduty then return end

if IsControlJustReleased(0, 38) then
if cache.vehicle then
vehicles.store(cache.vehicle)
end,
groups = helipad.groups,
distance = 1.5,
},
}
else
vehicles.openHelipad(helipad)
end

lib.hideTextUI()
end
end,
onExit = function()
lib.hideTextUI()
end,
})
end
end
Expand Down
24 changes: 13 additions & 11 deletions client/vehicles.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,36 @@ local function store(vehicle)
DeleteVehicle(vehicle)
end

---@param vehicle string
---@param vehicle CatalogueItem
---@param spawn vector4
local function takeOut(vehicle, spawn)
if cache.vehicle then
exports.qbx_core:Notify(locale('notify.in_vehicle'), 'error')
return
end

local netId = lib.callback.await('s_police:server:spawnVehicle', false, vehicle, spawn)
local netId = lib.callback.await('qbx_ems:server:spawnVehicle', false, vehicle, spawn)

lib.waitFor(function()
if NetworkDoesEntityExistWithNetworkId(netId) then
return NetToVeh(netId)
end
return NetworkDoesEntityExistWithNetworkId(netId)
end, locale('vehicles.something_wrong'))
end

---@param garage table
local function openGarage(garage)
local options = {}

for _, vehicle in pairs(garage.catalogue) do
for i = 1, #garage.catalogue do
local vehicle = garage.catalogue[i]

if vehicle.grade <= QBX.PlayerData.job.grade.level then
local title = ('%s %s'):format(VEHICLES[vehicle.name].brand, VEHICLES[vehicle.name].name)

options[#options + 1] = {
title = title,
arrow = true,
onSelect = function()
takeOut(vehicle.name, garage.spawn)
takeOut(vehicle, garage.spawn)
end,
}
end
Expand All @@ -53,15 +53,17 @@ end
local function openHelipad(helipad)
local options = {}

for _, heli in pairs(helipad.catalogue) do
if heli.grade <= QBX.PlayerData.job.grade.level then
local title = ('%s %s'):format(VEHICLES[heli.name].brand, VEHICLES[heli.name].name)
for i = 1, #helipad.catalogue do
local helicopter = helipad.catalogue[i]

if helicopter.grade <= QBX.PlayerData.job.grade.level then
local title = ('%s %s'):format(VEHICLES[helicopter.name].brand, VEHICLES[helicopter.name].name)

options[#options + 1] = {
title = title,
arrow = true,
onSelect = function()
takeOut(heli.name, helipad.spawn)
takeOut(helicopter, helipad.spawn)
end,
}
end
Expand Down
10 changes: 5 additions & 5 deletions locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@
"duty": "Clock In/Out",
"boss_menu": "Open Job Management",
"closet": "Open Medical Supply Closet",
"personal_stash": "Open Personal Stash",
"garage": "Open Garage",
"store_vehicle": "Store Vehicle",
"helipad": "Open Helipad",
"store_helicopter": "Store Helicopter"
"personal_stash": "Open Personal Stash"
},
"radial": {
"label": "EMS",
Expand All @@ -22,6 +18,10 @@
"not_around": "It looks like that person is not around right now..."
},
"vehicles": {
"open_helipad": "E - Open Helipad",
"store_helicopter": "E - Store Helicopter",
"open_garage": "E - Open Garage",
"store_vehicle": "E - Store Vehicle",
"garage_title": "EMS Garage",
"helipad_title": "EMS Helipad",
"not_helipad_grade": "You're not the appropriate grade to pilot a helicopter yet...",
Expand Down
9 changes: 5 additions & 4 deletions server/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,18 @@ local function registerSupplyCloset(hospital)
end

---@param source number
---@param model string
---@param vehicle table
---@param spawn vector4
lib.callback.register('qbx_police:server:spawnVehicle', function(source, model, spawn)
lib.callback.register('qbx_ems:server:spawnVehicle', function(source, vehicle, spawn)
local ped = GetPlayerPed(source)
local plate = ('EMS%s'):format(math.random(10000, 99999))
local netId, _ = qbx.spawnVehicle({
spawnSource = spawn,
model = model,
model = vehicle.name,
warp = ped,
props = {
plate = plate
plate = plate,
modLivery = vehicle.livery or 0
}
})

Expand Down
1 change: 1 addition & 0 deletions types.lua
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
---@class CatalogueItem
---@field name string
---@field grade number
---@field livery? number default is 0

---@class VehicleData
---@field coords vector3
Expand Down