qb-apartments & qb-housing
local QBCore = exports['qb-core']:GetCoreObject()
local function isResourceStarted(resourceName)
return GetResourceState(resourceName) == 'started'
end
Property = {
---@param stateid string
---@return table A list of properties with keys: value, label, coords<optional>
GetPlayerProperties = function(stateid)
local properties = {}
-- Fetch properties from qb-houses
if isResourceStarted('qb-houses') then
local houses = MySQL.query.await(
[[
SELECT
name as value,
label,
coords
FROM
houselocations
WHERE
citizenid = ?
]], { stateid }
)
for _, house in ipairs(houses) do
local coords = json.decode(house.coords)
table.insert(properties, {
value = house.value,
label = house.label,
coords = { x = coords.x, y = coords.y }
})
end
end
-- Fetch properties from qb-apartments
if isResourceStarted('qb-apartments') then
local apartmentRecord = MySQL.single.await(
'SELECT apartment FROM players WHERE citizenid = ?',
{ stateid }
)
if apartmentRecord and apartmentRecord.apartment then
local apartmentId = apartmentRecord.apartment
local apartmentData = Apartments.Locations[apartmentId]
if apartmentData then
local coords = apartmentData.coords and apartmentData.coords.enter
local coordsTable = coords and { x = coords.x, y = coords.y } or nil
table.insert(properties, {
value = apartmentId,
label = apartmentData.label or apartmentId,
coords = coordsTable
})
end
end
end
return properties
end
}
Last updated
Was this helpful?