Skip to content

Commit

Permalink
House garage fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
GhzGarage committed Jan 14, 2024
1 parent 80180c2 commit 29a2779
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
24 changes: 23 additions & 1 deletion client/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -322,14 +322,15 @@ local function CreateHouseZone(index, garage, zoneType)
data = {
indexgarage = index,
type = zoneType,
category = garage.category
}
})

if houseZone then
houseGarageZones[#houseGarageZones + 1] = houseZone

if not houseComboZones then
houseComboZones = ComboZone:Create(houseGarageZones, { name = 'houseComboZones', debugPoly = true })
houseComboZones = ComboZone:Create(houseGarageZones, { name = 'houseComboZones', debugPoly = false })
else
houseComboZones:AddZone(houseZone)
end
Expand Down Expand Up @@ -391,6 +392,21 @@ RegisterNetEvent('qb-garages:client:setHouseGarage', function(house, hasKey) --
elseif not hasKey and ZoneExists(zoneName) then
RemoveHouseZone(zoneName)
end
else
QBCore.Functions.TriggerCallback('qb-garages:server:getHouseGarage', function(garageInfo) -- create garage if not exist
local garageCoords = json.decode(garageInfo.garage)
Config.Garages[formattedHouseName] = {
houseName = house,
takeVehicle = vector3(garageCoords.x, garageCoords.y, garageCoords.z),
spawnPoint = {
vector4(garageCoords.x, garageCoords.y, garageCoords.z, garageCoords.w)
},
label = garageInfo.label,
type = 'house',
category = Config.VehicleClass['all']
}
TriggerServerEvent('qb-garages:server:syncGarage', Config.Garages)
end, house)
end
end)

Expand All @@ -399,27 +415,33 @@ RegisterNetEvent('qb-garages:client:houseGarageConfig', function(houseGarages)
local formattedHouseName = string.gsub(string.lower(garageConfig.label), ' ', '')
if garageConfig.takeVehicle and garageConfig.takeVehicle.x and garageConfig.takeVehicle.y and garageConfig.takeVehicle.z and garageConfig.takeVehicle.w then
Config.Garages[formattedHouseName] = {
houseName = house,
takeVehicle = vector3(garageConfig.takeVehicle.x, garageConfig.takeVehicle.y, garageConfig.takeVehicle.z),
spawnPoint = {
vector4(garageConfig.takeVehicle.x, garageConfig.takeVehicle.y, garageConfig.takeVehicle.z, garageConfig.takeVehicle.w)
},
label = garageConfig.label,
type = 'house',
category = Config.VehicleClass['all']
}
end
end
TriggerServerEvent('qb-garages:server:syncGarage', Config.Garages)
end)

RegisterNetEvent('qb-garages:client:addHouseGarage', function(house, garageInfo) -- event from housing on garage creation
local formattedHouseName = string.gsub(string.lower(house), ' ', '')
Config.Garages[formattedHouseName] = {
houseName = house,
takeVehicle = vector3(garageInfo.takeVehicle.x, garageInfo.takeVehicle.y, garageInfo.takeVehicle.z),
spawnPoint = {
vector4(garageInfo.takeVehicle.x, garageInfo.takeVehicle.y, garageInfo.takeVehicle.z, garageInfo.takeVehicle.w)
},
label = garageInfo.label,
type = 'house',
category = Config.VehicleClass['all']
}
TriggerServerEvent('qb-garages:server:syncGarage', Config.Garages)
end)

-- Handlers
Expand Down
2 changes: 1 addition & 1 deletion config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Config = {}
Config.AutoRespawn = true -- true == stores cars in garage on restart | false == doesnt modify car states
Config.VisuallyDamageCars = true -- true == damage car on spawn | false == no damage on spawn
Config.SharedGarages = false -- true == take any car from any garage | false == only take car from garage stored in
Config.ClassSystem = true -- true == restrict vehicles by class | false == any vehicle class in any garage
Config.ClassSystem = false -- true == restrict vehicles by class | false == any vehicle class in any garage
Config.FuelResource = 'LegacyFuel' -- supports any that has a GetFuel() and SetFuel() export
Config.Warp = true -- true == warp player into vehicle | false == vehicle spawns without warping

Expand Down
13 changes: 12 additions & 1 deletion server/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ end

-- Callbacks

QBCore.Functions.CreateCallback('qb-garages:server:getHouseGarage', function(_, cb, house)
local houseInfo = MySQL.single.await('SELECT * FROM houselocations WHERE name = ?', { house })
cb(houseInfo)
end)

QBCore.Functions.CreateCallback('qb-garages:server:GetGarageVehicles', function(source, cb, garage, type, category)
local Player = QBCore.Functions.GetPlayer(source)
if not Player then return end
Expand Down Expand Up @@ -144,7 +149,7 @@ QBCore.Functions.CreateCallback('qb-garages:server:canDeposit', function(source,
cb(false)
return
end
if type == 'house' and not exports['qb-houses']:hasKey(Player.PlayerData.license, Player.PlayerData.citizenid, Config.HouseGarages[garage].label) then
if type == 'house' and not exports['qb-houses']:hasKey(Player.PlayerData.license, Player.PlayerData.citizenid, Config.Garages[garage].houseName) then
cb(false)
return
end
Expand Down Expand Up @@ -212,6 +217,12 @@ RegisterNetEvent('qb-garages:server:PayDepotPrice', function(data)
end)
end)

-- House Garages

RegisterNetEvent('qb-garages:server:syncGarage', function(updatedGarages)
Config.Garages = updatedGarages
end)

--Call from qb-phone

QBCore.Functions.CreateCallback('qb-garages:server:GetPlayerVehicles', function(source, cb)
Expand Down

0 comments on commit 29a2779

Please sign in to comment.