LB Tablet
Integration for lb tablet with bcs_housing
Add bcs_housing
into the auto detection of housing scripts.
lb-tablet/shared/functions
local housingScripts = {
"loaf_housing",
"qb-houses",
"qs-housing",
"bcs_housing"
}
Add the server code integration for the housing
lb-tablet/server/custom/housing/bcs_housing.lua
if Config.HousingScript ~= "bcs_housing" then
return
end
local resourceName = "bcs_housing"
while GetResourceState(resourceName) ~= "started" do
debugprint("Waiting for housing script to start...")
Wait(1000)
end
local searchPropertiesQuery = ""
if Config.Framework == "esx" then
searchPropertiesQuery = [[
SELECT
p.owner,
p.identifier,
CONCAT(u.firstname, ' ', u.lastname) AS `name`
FROM house_owned p
LEFT JOIN users u
ON u.identifier = p.owner
WHERE
CONCAT(u.firstname, ' ', u.lastname) LIKE ?
OR p.identifier LIKE ?
LIMIT ?, ?
]]
elseif Config.Framework == "qb" then
searchPropertiesQuery = [[
SELECT
p.owner,
p.identifier,
CONCAT(JSON_VALUE(u.charinfo, '$.firstname'), ' ', JSON_VALUE(u.charinfo, '$.lastname')) AS `name`
FROM house_owned p
LEFT JOIN players u
ON u.citizenid = p.owner
WHERE
CONCAT(JSON_VALUE(u.charinfo, '$.firstname'), ' ', JSON_VALUE(u.charinfo, '$.lastname')) LIKE ?
OR p.identifier LIKE ?
LIMIT ?, ?
]]
end
local function EncodePropertyId(owner, id)
return "owner:" .. owner .. ",id:" .. id
end
local function DecodePropertyId(id)
local owner, propertyId = string.match(id, "owner:(.+),id:([^,]+)$")
return owner, propertyId and tonumber(propertyId)
end
local function FormatPropery(property)
local propertyData = exports.bcs_housing:GetHome(property.identifier)
property.label = propertyData.name
property.id = EncodePropertyId(property.owner, property.identifier)
local entry = propertyData.complex == 'Flat' and propertyData.data.flat.coords or propertyData.entry
local owner = property.owner
property.owner = {
name = GetCharacterNameFromIdentifier(owner) or owner,
identifier = owner
}
property.address = 'Unknown'
property.name = nil
property.propertyid = nil
if entry then
property.location = {
x = entry.x,
y = entry.y,
}
end
return property
end
---@param query string
---@param page? number
---@return table[]
function SearchProperties(query, page)
query = "%" .. query .. "%"
local properties = MySQL.query.await(
searchPropertiesQuery,
{ query, query, (page or 0) * 10, 10 }
)
local list = {}
for i = 1, #properties do
list[#list + 1] = FormatPropery(properties[i])
end
return list
end
function GetProperty(id)
local owner, propertyId = DecodePropertyId(id)
if not owner or not propertyId then
debugprint("Failed to decode property id", id)
return
end
local property = exports.bcs_housing:GetHome(tostring(propertyId))
if property and property.complex == 'Apartment' then
for j = 1, #property.apartments do
if property.apartments[j].owner == owner then
for k, v in pairs(property.apartments[j]) do
property[k] = v
end
end
end
end
if not property then
return
end
return FormatPropery(property)
end
---@param identifier string
---@return { id: string, label: string }[]
function GetPlayerProperties(identifier)
local properties = exports.bcs_housing:GetOwnedHomeKeys(identifier)
for i = 1, #properties do
local property = properties[i]
properties[i] = {
id = EncodePropertyId(identifier, property.identifier),
label = property.name
}
end
return properties
end
Last updated on