Skip to main content

qbx_spawn

Integration for housing for qbx_spawn

Find: qbx_spawn:server:getHouses

lib.callback.register('qbx_spawn:server:getHouses', function(source)
local player = exports.qbx_core:GetPlayer(source)
local houseData = {}
local playerHouses = MySQL.query.await('SELECT house FROM player_houses WHERE citizenid = ?', {player.PlayerData.citizenid})
for i = 1, #playerHouses do
local name = playerHouses[i].house
local locationData = MySQL.single.await('SELECT `coords`, `label` FROM houselocations WHERE name = ?', {name})
houseData[#houseData+1] = {
label = locationData.label,
coords = json.decode(locationData.coords).enter
}
end

return houseData
end)

Replace:

lib.callback.register('qbx_spawn:server:getHouses', function(source)
local player = exports.qbx_core:GetPlayer(source)
local houseData = {}
local playerHouses = exports.bcs_housing:GetOwnedHomeKeys(player.PlayerData.citizenid)
for i = 1, #playerHouses do
local house = playerHouses[i]
local entry = house.entry
houseData[#houseData + 1] = {
label = house.name,
coords = vec4(entry.x, entry.y, entry.z, entry.w),
}
end
return houseData
end)

Follow this to using Starter Apartment​

Find: inputHandler

local function inputHandler()
while DoesCamExist(previewCam) do
if IsControlJustReleased(0, 188) then
previousButtonID = currentButtonID
currentButtonID -= 1

if currentButtonID < 1 then
currentButtonID = #spawns
end

updateScaleform()
elseif IsControlJustReleased(0, 187) then
previousButtonID = currentButtonID
currentButtonID += 1

if currentButtonID > #spawns then
currentButtonID = 1
end

updateScaleform()
elseif IsControlJustReleased(0, 191) then
DoScreenFadeOut(1000)

while not IsScreenFadedOut() do
Wait(0)
end

TriggerServerEvent('QBCore:Server:OnPlayerLoaded')
TriggerEvent('QBCore:Client:OnPlayerLoaded')
FreezeEntityPosition(cache.ped, false)

local coords = spawns[currentButtonID].coords

SetEntityCoords(cache.ped, coords.x, coords.y, coords.z, false, false, false, false)
SetEntityHeading(cache.ped, coords.w or 0.0)
DoScreenFadeIn(1000)
break
end

Wait(0)
end
stopCamera()
end

Replace:

local function inputHandler()
while DoesCamExist(previewCam) do
if IsControlJustReleased(0, 188) then
previousButtonID = currentButtonID
currentButtonID -= 1

if currentButtonID < 1 then
currentButtonID = #spawns
end

updateScaleform()
elseif IsControlJustReleased(0, 187) then
previousButtonID = currentButtonID
currentButtonID += 1

if currentButtonID > #spawns then
currentButtonID = 1
end

updateScaleform()
elseif IsControlJustReleased(0, 191) then
DoScreenFadeOut(1000)

while not IsScreenFadedOut() do
Wait(0)
end
TriggerServerEvent('QBCore:Server:OnPlayerLoaded')
TriggerEvent('QBCore:Client:OnPlayerLoaded')
FreezeEntityPosition(cache.ped, false)
if spawns[currentButtonID].id then
TriggerServerEvent('Housing:server:CreateApartment', spawns[currentButtonID].id)
else
local coords = spawns[currentButtonID].coords
SetEntityCoords(cache.ped, coords.x, coords.y, coords.z, false, false, false, false)
SetEntityHeading(cache.ped, coords.w or 0.0)
end
DoScreenFadeIn(1000)
break
end

Wait(0)
end
stopCamera()
end

Find: qb-spawn:client:setupSpawns

AddEventHandler('qb-spawn:client:setupSpawns', function()
spawns = {}

spawns[#spawns+1] = {
label = 'last_location',
coords = lib.callback.await('qbx_spawn:server:getLastLocation')
}

for i = 1, #config.spawns do
spawns[#spawns+1] = config.spawns[i]
end

local houses = lib.callback.await('qbx_spawn:server:getHouses')
for i = 1, #houses do
spawns[#spawns+1] = houses[i]
end

Wait(400)

managePlayer()
setupCamera()
setupMap()

Wait(400)

scaleformDetails(currentButtonID)
inputHandler()
end)

Replace:

AddEventHandler('qb-spawn:client:setupSpawns', function(_, new, appartments)
spawns = {}
if new then
for k, v in pairs(appartments) do
local home = exports.bcs_housing:GetHome(k)
local entry = home.entry or home.properties.entry
spawns[#spawns + 1] = {
id = k,
label = v.name,
coords = vec4(entry.x, entry.y, entry.z, entry.w)
}
end
else
spawns[#spawns + 1] = {
label = 'last_location',
coords = lib.callback.await('qbx_spawn:server:getLastLocation')
}
for i = 1, #config.spawns do
spawns[#spawns + 1] = config.spawns[i]
end
local houses = lib.callback.await('qbx_spawn:server:getHouses')
for i = 1, #houses do
spawns[#spawns + 1] = houses[i]
end
end
Wait(400)
managePlayer()
setupCamera()
setupMap()
Wait(400)
scaleformDetails(currentButtonID)
inputHandler()
end)