qb-houses
Applying compatibility
1.Registering Garage
Headover to the qb-houses/server/main.lua and find main threads:
CreateThread(function()
local HouseGarages = {}
local result = MySQL.query.await('SELECT * FROM houselocations', {})
if result[1] then
for _, v in pairs(result) do
local owned = false
if tonumber(v.owned) == 1 then
owned = true
end
local garage = json.decode(v.garage) or {}
Config.Houses[v.name] = {
coords = json.decode(v.coords),
owned = owned,
price = v.price,
locked = true,
adress = v.label,
tier = v.tier,
garage = garage,
decorations = {}
}
HouseGarages[v.name] = {
label = v.label,
takeVehicle = garage
}
end
end
TriggerClientEvent('qb-garages:client:houseGarageConfig', -1, HouseGarages)
TriggerClientEvent('qb-houses:client:setHouseConfig', -1, Config.Houses)
end)
CreateThread(function()
while true do
if not housesLoaded then
MySQL.query('SELECT * FROM player_houses', {}, function(houses)
if houses then
for _, house in pairs(houses) do
houseowneridentifier[house.house] = house.identifier
houseownercid[house.house] = house.citizenid
housekeyholders[house.house] = json.decode(house.keyholders)
end
end
end)
housesLoaded = true
end
Wait(7)
end
end)Then replace it with:
CreateThread(function()
local HouseGarages = {}
local result = MySQL.query.await('SELECT * FROM houselocations', {})
if result[1] then
for _, v in pairs(result) do
local owned = false
if tonumber(v.owned) == 1 then
owned = true
end
local garage = json.decode(v.garage) or {}
Config.Houses[v.name] = {
coords = json.decode(v.coords),
owned = owned,
price = v.price,
locked = true,
adress = v.label,
tier = v.tier,
garage = garage,
decorations = {}
}
HouseGarages[v.name] = {
label = v.label,
takeVehicle = garage
}
end
end
--[[
ZSX_GARAGES COMPATIBILITY
[-] START
]]
if GetResourceState("ZSX_Garages") ~= "started" then
TriggerClientEvent('qb-garages:client:househouseData.garage', -1, HouseGarages)
end
--[[
ZSX_GARAGES COMPATIBILITY
[-] END
]]
TriggerClientEvent('qb-houses:client:setHouseConfig', -1, Config.Houses)
end)
CreateThread(function()
while true do
if not housesLoaded then
MySQL.query('SELECT * FROM player_houses', {}, function(houses)
if houses then
for _, house in pairs(houses) do
houseowneridentifier[house.house] = house.identifier
houseownercid[house.house] = house.citizenid
housekeyholders[house.house] = json.decode(house.keyholders)
end
end
end)
housesLoaded = true
end
Wait(7)
end
end)
--[[
ZSX_GARAGES COMPATIBILITY
[-] START
]]
Citizen.CreateThread(function()
Wait(2000)
if GetResourceState("ZSX_Garages") == "missing" then return end
if next(Config.Houses) == nil then
while next(Config.Houses) == nil do
Wait(50)
end
end
if next(houseownercid) == nil then
while next(houseownercid) == nil do
Wait(50)
end
end
for _, houseData in pairs(Config.Houses) do
if next(houseData.garage) and GetResourceState("ZSX_Garages") == "started" then
local players = {}
if houseownercid[houseData.name] then
table.insert(players, houseownercid[houseData.name])
end
local coordinates = { vector4(houseData.garage.takeVehicle.x, houseData.garage.takeVehicle.y, houseData.garage.takeVehicle.z, houseData.garage.takeVehicle.w) }
exports['ZSX_Garages']:AddTempGarage("qb-houses_" .. houseData.name, houseData.address, true, 'player', players, coordinates)
end
end
end)
--[[
ZSX_GARAGES COMPATIBILITY
[-] END
]]2.Updating Garage
Headover to the qb-houses/server/main.lua, find event called qb-houses:server:addGarage and replace it with:
RegisterNetEvent('qb-houses:server:addGarage', function(house, coords)
local src = source
MySQL.update('UPDATE houselocations SET garage = ? WHERE name = ?', { json.encode(coords), house })
local garageInfo = {
label = Config.Houses[house].adress,
takeVehicle = coords
}
--[[
ZSX_GARAGES COMPATIBILITY
[-] START
]]
if GetResourceState("ZSX_Garages") ~= "started" then
TriggerClientEvent('qb-garages:client:addHouseGarage', -1, house, garageInfo)
else
local players = {}
if houseownercid[house] then
table.insert(players, houseownercid[houseData.name])
end
local coordinates = { vector4(coords.x, coords.y, coords.z, coords.w) }
exports['ZSX_Garages']:AddTempGarage("qb-houses_" .. Config.Houses[house].name, Config.Houses[house].address, true, 'player', players, coordinates)
end
--[[
ZSX_GARAGES COMPATIBILITY
[-] END
]]
TriggerClientEvent('QBCore:Notify', src, Lang:t('info.added_garage', { value = garageInfo.label }))
end)3.Updating Owner
Headover to the qb-houses/server/main.lua, find event called qb-houses:server:addGarage and replace it with:
RegisterNetEvent('qb-houses:server:buyHouse', function(house)
local src = source
local pData = QBCore.Functions.GetPlayer(src)
local price = Config.Houses[house].price
local HousePrice = math.ceil(price * 1.21)
local bankBalance = pData.PlayerData.money['bank']
local isOwned = isHouseOwned(house)
if isOwned then
TriggerClientEvent('QBCore:Notify', src, Lang:t('error.already_owned'), 'error')
CancelEvent()
return
end
if (bankBalance >= HousePrice) then
houseowneridentifier[house] = pData.PlayerData.license
houseownercid[house] = pData.PlayerData.citizenid
housekeyholders[house] = {
[1] = pData.PlayerData.citizenid
}
MySQL.insert('INSERT INTO player_houses (house, identifier, citizenid, keyholders) VALUES (?, ?, ?, ?)', { house, pData.PlayerData.license, pData.PlayerData.citizenid, json.encode(housekeyholders[house]) })
MySQL.update('UPDATE houselocations SET owned = ? WHERE name = ?', { 1, house })
TriggerClientEvent('qb-houses:client:SetClosestHouse', src)
TriggerClientEvent('qb-house:client:RefreshHouseTargets', src)
pData.Functions.RemoveMoney('bank', HousePrice, 'bought-house') -- 21% Extra house costs
exports['qb-banking']:AddMoney('realestate', (HousePrice / 100) * math.random(18, 25), 'House purchase')
TriggerEvent('qb-log:server:CreateLog', 'house', Lang:t('log.house_purchased'), 'green', Lang:t('log.house_purchased_by', { house = house:upper(), price = HousePrice, firstname = pData.PlayerData.charinfo.firstname, lastname = pData.PlayerData.charinfo.lastname }))
TriggerClientEvent('QBCore:Notify', src, Lang:t('success.house_purchased'), 'success', 5000)
--[[
ZSX_GARAGES COMPATIBILITY
[-] START
]]
local players = {}
if houseownercid[house] then
table.insert(players, houseownercid[houseData.name])
end
exports['ZSX_Garages']:UpdateTempGaragePlayerList("qb-houses_" .. Config.Houses[house].name, players)
--[[
ZSX_GARAGES COMPATIBILITY
[-] END
]]
else
TriggerClientEvent('QBCore:Notify', src, Lang:t('error.not_enough_money'), 'error')
end
end)Last updated