lb-tablet
Navigate to the lb-tablet/config/config.lua
Find the
Config.HousingScriptoption and customize:
CConfig.HousingScript = "vms_housing"Navigate to the lb-tablet/server/custom/housing
Create a new lua file named
vms_housing.luaPaste all of the following code into the
vms_housing.luafile
if Config.HousingScript ~= "vms_housing" then
return
end
local resourceName = "vms_housing"
while GetResourceState(resourceName) ~= "started" do
debugprint("Waiting for housing script to start...")
Wait(1000)
end
local selectPropertyQuery = [[
SELECT
p.id,
COALESCE(NULLIF(p.owner, ''), NULLIF(p.renter, '')) AS owner,
CASE
WHEN NULLIF(p.owner, '') IS NOT NULL THEN p.owner_name
ELSE p.renter_name
END AS `name`
FROM houses p
]]
local searchPropertiesQuery = selectPropertyQuery .. [[
WHERE
COALESCE(NULLIF(p.owner, ''), NULLIF(p.renter, '')) IS NOT NULL
AND (
CASE
WHEN NULLIF(p.owner, '') IS NOT NULL THEN p.owner_name
ELSE p.renter_name
END LIKE ?
OR CAST(p.id AS CHAR) LIKE ?
)
{WHERE_FILTER}
LIMIT ?, ?
]]
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['vms_housing']:GetProperty(property.id)
property.label = propertyData.name
property.id = EncodePropertyId(property.owner, property.id)
property.owner = {
name = property.name,
identifier = property.owner
}
property.name = nil
property.propertyid = nil
property.address = propertyData.address
if propertyData.type == 'mlo' then
property.location = {x = propertyData.metadata.menu.x, y = propertyData.metadata.menu.y}
else
if propertyData.object_id then
local object = exports['vms_housing']:GetProperty(propertyData.object_id)
if object.type == 'building' then
property.location = {x = object.metadata.enter.x, y = object.metadata.enter.y}
goto skip
end
end
property.location = {x = propertyData.metadata.enter.x, y = propertyData.metadata.enter.y}
::skip::
end
return property
end
function SearchProperties(query, page, filter)
local params = { "%" .. query .. "%", "%" .. query .. "%" }
local where = ""
local searchQuery = searchPropertiesQuery
if filter.tags then
for i = 1, #filter.tags do
where = where .. " AND EXISTS (SELECT 1 FROM lbtablet_police_profile_tags ppt WHERE ppt.id COLLATE utf8mb4_unicode_ci = (CONCAT('house:owner:', p.owner, ',id:', p.id) COLLATE utf8mb4_unicode_ci) AND ppt.tag_id = ?)"
params[#params+1] = filter.tags[i]
end
end
searchQuery = searchQuery:gsub("{WHERE_FILTER}", where)
params[#params+1] = (page or 0) * 10
params[#params+1] = 10
local properties = MySQL.query.await(
searchQuery,
params
)
for i = 1, #properties do
properties[i] = FormatPropery(properties[i])
end
return properties
end
function GetProperty(identifier)
local owner, id = DecodePropertyId(identifier)
local property = exports['vms_housing']:GetProperty(id)
if not property then
debugprint("Failed to decode property id", id)
return
end
return FormatPropery({
id = id,
owner = property.owner or property.renter,
name = property.owner_name or property.renter_name,
})
end
function GetPlayerProperties(identifier)
local propertiesList = exports['vms_housing']:GetPlayerProperties(identifier)
local properties = {}
for k, v in pairs(propertiesList) do
table.insert(properties, {
id = v.id,
name = v.name
})
end
return properties
endLast updated