Skip to content

Commit

Permalink
fix: check if the vehicle spawn point is free of other vehicles and d…
Browse files Browse the repository at this point in the history
…efault the drop point to the spawn point (#120)

* Fix [Vehicle Spawn #115] + Fix dropPoint to Default to spawn or coords

* Update client/main.lua

Co-authored-by: Matthew <[email protected]>

* Update server/spawn-vehicle.lua

Co-authored-by: Matthew <[email protected]>

* Added distanceCheck to the configuration

* fix  whitespace

* chore(config/server): update wording for config variable

---------

Co-authored-by: Matthew <[email protected]>
Co-authored-by: Solareon <[email protected]>
  • Loading branch information
3 people authored Aug 16, 2024
1 parent 12001d9 commit 77af8b7
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
1 change: 1 addition & 0 deletions client/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ end
---@param accessPointIndex integer
local function createZones(garageName, garage, accessPoint, accessPointIndex)
CreateThread(function()
accessPoint.dropPoint = accessPoint.dropPoint or accessPoint.spawn
local dropZone, coordsZone
lib.zones.sphere({
coords = accessPoint.coords,
Expand Down
4 changes: 2 additions & 2 deletions config/server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ return {
autoRespawn = false, -- True == auto respawn cars that are outside into your garage on script restart, false == does not put them into your garage and players have to go to the impound
warpInVehicle = false, -- If false, player will no longer warp into vehicle upon taking the vehicle out.
doorsLocked = true, -- If true, the doors will be locked upon taking the vehicle out.

distanceCheck = 5.0, -- The distance that needs to bee clear to let the vehicle spawn, this prevents vehicles stacking on top of each other
---calculates the automatic impound fee.
---@param vehicleId integer
---@param modelName string
Expand All @@ -22,7 +22,7 @@ return {
---@field coords vector4 where the garage menu can be accessed from
---@field blip? GarageBlip
---@field spawn? vector4 where the vehicle will spawn. Defaults to coords
---@field dropPoint? vector3 where a vehicle can be stored, Defaults to coords
---@field dropPoint? vector3 where a vehicle can be stored, Defaults to spawn or coords

---@class GarageConfig
---@field label string -- Label for the garage
Expand Down
1 change: 1 addition & 0 deletions locales/en.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"error": {
"no_space": "Another vehicle has occupied the space.",
"no_access": "You don't have access to this garage",
"no_vehicles": "You currently have no vehicles at this location...",
"not_impound": "Your vehicle is not in impound",
Expand Down
11 changes: 10 additions & 1 deletion server/spawn-vehicle.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ lib.callback.register('qbx_garages:server:spawnVehicle', function (source, vehic
end
local garageType = GetGarageType(garageName)

local spawnCoords = accessPoint.spawn or accessPoint.coords
if Config.distanceCheck then
local vec3Coords = vec3(spawnCoords.x, spawnCoords.y, spawnCoords.z)
local nearbyVehicle = lib.getClosestVehicle(vec3Coords, Config.distanceCheck, false)
if nearbyVehicle then
exports.qbx_core:Notify(source, locale('error.no_space'), 'error')
return
end
end

local filter = GetPlayerVehicleFilter(source, garageName)
local playerVehicle = exports.qbx_vehicles:GetPlayerVehicle(vehicleId, filter)
if not playerVehicle then
Expand All @@ -33,7 +43,6 @@ lib.callback.register('qbx_garages:server:spawnVehicle', function (source, vehic
end

local warpPed = Config.warpInVehicle and GetPlayerPed(source)
local spawnCoords = accessPoint.spawn or accessPoint.coords
local netId, veh = qbx.spawnVehicle({ spawnSource = spawnCoords, model = playerVehicle.props.model, props = playerVehicle.props, warp = warpPed})

if Config.doorsLocked then
Expand Down

0 comments on commit 77af8b7

Please sign in to comment.