Files
red-valley/resources/[framework]/[addons]/qs-smartphone-pro/server/custom/garage/jg-advancedgarages.lua
2026-03-29 21:41:17 +03:00

96 lines
2.6 KiB
Lua

if Config.Garage ~= 'jg-advancedgarages' then
return
end
RegisterNetEvent('phone:setVehicleToOutSide', function(plate)
local str = [[
UPDATE owned_vehicles
SET in_garage = 0
WHERE plate = ?
]]
if Config.Framework == 'qb' then
str = [[
UPDATE player_vehicles
SET in_garage = 0
WHERE plate = ?
]]
end
MySQL.Sync.execute(str, { plate })
end)
function getGarageData(identifier, plate)
local str = [[
SELECT * FROM owned_vehicles WHERE owner = ? AND (type = 'vehicle' OR type = 'car')
]]
if Config.Framework == 'qb' then
str = [[
SELECT * FROM player_vehicles WHERE citizenid = ?
]]
end
if plate then
str = str .. ([[
AND plate = "%s"
]]):format(plate)
end
local result = MySQL.Sync.fetchAll(str, { identifier })
if not result[1] then return false end
local data = {}
if Config.Framework == 'qb' then
for k, v in pairs(result) do
local inGarage = v.in_garage
local garageId = v.garage_id
local impound = v.impound
if not inGarage then
garageId = v.impound == 1 and 'IMPOUND' or 'OUT'
end
if impound == 1 then
garageId = v.garage_id
inGarage = false
end
table.insert(data, {
name = v.vehicle,
plate = v.plate,
inGarage = inGarage,
fuel = v.fuel * 10 or 1000,
engine = v.engine or 1000,
body = v.body or 1000,
vehicle = json.decode(v.mods),
garage = garageId,
})
end
else
for k, v in pairs(result) do
local vehicle = json.decode(v.vehicle)
if not vehicle then return end
local inGarage = v.in_garage
local garageId = v.garage_id
local impound = v.impound
if not inGarage then
garageId = 'OUT'
end
if impound == 1 then
garageId = v.impound == 1 and 'IMPOUND' or 'OUT'
inGarage = false
end
table.insert(data, {
name = vehicle.model,
plate = v.plate,
inGarage = inGarage,
fuel = v.fuel * 10 or 1000,
engine = vehicle.engine or 1000,
body = vehicle.body or 1000,
vehicle = json.decode(v.vehicle),
garage = garageId,
})
end
end
return data
end