ps-housing

Applying compatibility

chevron-right1.Registering Garagehashtag

Find function Property:new in ps-housing/server/sv_property.lua and replace with:

function Property:new(propertyData)
    local self = setmetatable({}, Property)

    self.property_id = tostring(propertyData.property_id)
    self.propertyData = propertyData

    self.playersInside = {}
    self.playersInGarden = {}
    self.playersDoorbell = {}

    local stashName = ("property_%s"):format(propertyData.property_id)
    local stashConfig = Config.Shells[propertyData.shell].stash
    --[[
        ZSX_GARAGES COMPATIBILITY
        [-] START
    ]]
    if self.propertyData.garage_data then
        local players = {}

        if self.propertyData.owner then
            table.insert(players, self.propertyData.owner)
        end

        local coordinates = { vector4(self.propertyData.garage_data.x, self.propertyData.garage_data.y, self.propertyData.garage_data.z, self.propertyData.garage_data.h) }
        exports['ZSX_Garages']:AddTempGarage("ps-housing_" .. self.property_id, "Property #" .. self.property_id, true, 'player', players, coordinates)
    end
    
    --[[
        ZSX_GARAGES COMPATIBILITY
        [-] END
    ]]

    for k, v in ipairs(propertyData.furnitures) do
        if v.type == 'storage' then
            Framework[Config.Inventory].RegisterInventory(k == 1 and stashName or stashName..v.id, 'Property: ' ..  (propertyData.street or propertyData.apartment or 'Unknown') .. ' #'.. propertyData.property_id or propertyData.apartment or stashName, stashConfig)
        end
    end

    return self
end
chevron-right2.Updating Ownerhashtag

Find function Property:UpdateOwner in ps-housing/server/sv_property.lua and replace with:

function Property:UpdateOwner(data)
    local targetSrc = data.targetSrc
    local realtorSrc = data.realtorSrc

    if not realtorSrc then Debug("No Realtor Src found") return end
    if not targetSrc then Debug("No Target Src found") return end

    local previousOwner = self.propertyData.owner

    local targetPlayer  = QBCore.Functions.GetPlayer(tonumber(targetSrc))
    if not targetPlayer then return end

    local PlayerData = targetPlayer.PlayerData
    local bank = PlayerData.money.bank
    local citizenid = PlayerData.citizenid

    self:addMloDoorsAccess(citizenid)
    if self.propertyData.shell == 'mlo' and DoorResource == 'qb' then
        Framework[Config.Notify].Notify(targetSrc, "Go far away and come back for the door to update and open/close.", "error")
    end

    if self.propertyData.owner == citizenid then
        Framework[Config.Notify].Notify(targetSrc, "You already own this property", "error")
        Framework[Config.Notify].Notify(realtorSrc, "Client already owns this property", "error")
        return
    end

    --add callback 
    local targetAllow = lib.callback.await("ps-housing:cb:confirmPurchase", targetSrc, self.propertyData.price, self.propertyData.street, self.propertyData.property_id)

    if targetAllow ~= "confirm" then
        Framework[Config.Notify].Notify(targetSrc, "You did not confirm the purchase", "info")
        Framework[Config.Notify].Notify(realtorSrc, "Client did not confirm the purchase", "error")
        return
    end

    if bank < self.propertyData.price then
                Framework[Config.Notify].Notify(targetSrc, "You do not have enough money in your bank account", "error")
            Framework[Config.Notify].Notify(realtorSrc, "Client does not have enough money in their bank account", "error")
        return
    end

    targetPlayer.Functions.RemoveMoney('bank', self.propertyData.price, "Bought Property: " .. self.propertyData.street .. " " .. self.property_id)

    local prevPlayer = QBCore.Functions.GetPlayerByCitizenId(previousOwner)
    local realtor = QBCore.Functions.GetPlayer(tonumber(realtorSrc))
    local realtorGradeLevel = realtor.PlayerData.job.grade.level

    local commission = math.floor(self.propertyData.price * Config.Commissions[realtorGradeLevel])

    local totalAfterCommission = self.propertyData.price - commission

    if Config.QBManagement then
        exports['qb-banking']:AddMoney(realtor.PlayerData.job.name, totalAfterCommission)
    else
        if prevPlayer ~= nil then
            Framework[Config.Notify].Notify(prevPlayer.PlayerData.source, "Sold Property: " .. self.propertyData.street .. " " .. self.property_id, "success")
            prevPlayer.Functions.AddMoney('bank', totalAfterCommission, "Sold Property: " .. self.propertyData.street .. " " .. self.property_id)
        elseif previousOwner then
            MySQL.Async.execute('UPDATE `players` SET `bank` = `bank` + @price WHERE `citizenid` = @citizenid', {
                ['@citizenid'] = previousOwner,
                ['@price'] = totalAfterCommission
            })
        end
    end
    
    realtor.Functions.AddMoney('bank', commission, "Commission from Property: " .. self.propertyData.street .. " " .. self.property_id)

    self.propertyData.owner = citizenid

    MySQL.update("UPDATE properties SET owner_citizenid = @owner_citizenid, for_sale = @for_sale WHERE property_id = @property_id", {
        ["@owner_citizenid"] = citizenid,
        ["@for_sale"] = 0,
        ["@property_id"] = self.property_id
    })

    self.propertyData.furnitures = {} -- to be fetched on enter

    --[[
        ZSX_GARAGES COMPATIBILITY
        [-] START
    ]]

    local players = {}
    if self.propertyData.owner then
        table.insert(players, self.propertyData.owner)
    end
    exports['ZSX_Garages']:UpdateTempGaragePlayerList("ps-housing_" .. self.property_id, players)

    --[[
        ZSX_GARAGES COMPATIBILITY
        [-] END
    ]]

    TriggerClientEvent("ps-housing:client:updateProperty", -1, "UpdateOwner", self.property_id, citizenid)
    TriggerClientEvent("ps-housing:client:updateProperty", -1, "UpdateForSale", self.property_id, 0)
    
    Framework[Config.Logs].SendLog("**House Bought** by: **"..PlayerData.charinfo.firstname.." "..PlayerData.charinfo.lastname.."** for $"..self.propertyData.price.." from **"..realtor.PlayerData.charinfo.firstname.." "..realtor.PlayerData.charinfo.lastname.."** !")

    Framework[Config.Notify].Notify(targetSrc, "You have bought the property for $"..self.propertyData.price, "success")
    Framework[Config.Notify].Notify(realtorSrc, "Client has bought the property for $"..self.propertyData.price, "success")
end
chevron-right3.Updating Garagehashtag

Find function Property:UpdateGarage in ps-housing/server/sv_property.lua and replace with:

function Property:UpdateGarage(data)
    local garage = data.garage
    local realtorSrc = data.realtorSrc

    local newData = {}

    if data ~= nil then 
        newData = {
            x = math.floor(garage.x * 10000) / 10000,
            y = math.floor(garage.y * 10000) / 10000,
            z = math.floor(garage.z * 10000) / 10000,
            h = math.floor(garage.h * 10000) / 10000,
            length = garage.length or 3.0,
            width = garage.width or 5.0,
        }
    end

    self.propertyData.garage_data = newData

    MySQL.update("UPDATE properties SET garage_data = @garageCoords WHERE property_id = @property_id", {
        ["@garageCoords"] = json.encode(newData),
        ["@property_id"] = self.property_id
    })

    --[[
        ZSX_GARAGES COMPATIBILITY
        [-] START
    ]]

    local coordinates = { vector4(self.propertyData.garage_data.x, self.propertyData.garage_data.y, self.propertyData.garage_data.z, self.propertyData.garage_data.h) }

    exports['ZSX_Garages']:UpdateTempGarageCoords("ps-housing_" .. self.property_id, coordinates)

    --[[
        ZSX_GARAGES COMPATIBILITY
        [-] END
    ]]
    
    TriggerClientEvent("ps-housing:client:updateProperty", -1, "UpdateGarage", self.property_id, newData)

    Framework[Config.Logs].SendLog("**Changed Garage** of property with id: " .. self.property_id .. " by: " .. GetPlayerName(realtorSrc))

    Debug("Changed Garage of property with id: " .. self.property_id, "by: " .. GetPlayerName(realtorSrc))
end
chevron-right4.Deleting Garagehashtag

Find function Property:DeleteProperty in ps-housing/server/sv_property.lua and replace with:

function Property:DeleteProperty(data)
    local realtorSrc = data.realtorSrc
    local propertyid = self.property_id
    local realtorName = GetPlayerName(realtorSrc)

    MySQL.Async.execute("DELETE FROM properties WHERE property_id = @property_id", {
        ["@property_id"] = propertyid
    }, function (rowsChanged)
        if rowsChanged > 0 then
            Debug("Deleted property with id: " .. propertyid, "by: " .. realtorName)
        end
    end)

    TriggerClientEvent("ps-housing:client:removeProperty", -1, propertyid)

    --[[
        ZSX_GARAGES COMPATIBILITY
        [-] START
    ]]

    exports['ZSX_Garages']:RemoveTempGarage("ps-housing_" .. propertyId)

    --[[
        ZSX_GARAGES COMPATIBILITY
        [-] END
    ]]

    Framework[Config.Notify].Notify(realtorSrc, "Property with id: " .. propertyid .." has been removed.", "info")

    Framework[Config.Logs].SendLog("**Property Deleted** with id: " .. propertyid .. " by: " .. realtorName)

    PropertiesTable[propertyid] = nil
    self = nil

    Debug("Deleted property with id: " .. propertyid, "by: " .. realtorName)
end
chevron-right5.Removing old compatibilitieshashtag

Find functions Property:RegisterGarageZone and Property:UnregisterGarageZone in ps-housing/client/cl_property.lua and replace with:

triangle-exclamation
function Property:RegisterGarageZone()
    if not next(self.propertyData.garage_data) then return end
    if GetResourceState("ZSX_Garages") == "started" then return end
    if not (self.has_access or self.owner) or not self.owner then
        return
    end

    local garageData = self.propertyData.garage_data
    local label = self.propertyData.street .. self.property_id .. " Garage"

    local isQbx = GetResourceState('qbx_garages') == 'started'
    local coords = vec4(garageData.x, garageData.y, garageData.z, garageData.h)

    if isQbx then
        TriggerServerEvent('ps-housing:server:qbxRegisterHouse', self.property_id)
    else
        TriggerEvent("qb-garages:client:addHouseGarage", self.property_id, {
            takeVehicle = {
                x = garageData.x,
                y = garageData.y,
                z = garageData.z,
                w = garageData.h
            },
            type = "house",
            label = label,
        })
    end
    if not isQbx then
        self.garageZone = lib.zones.box({
            coords = coords.xyz,
            size = vector3(garageData.length + 5.0, garageData.width + 5.0, 3.5),
            rotation = coords.w,
            debug = Config.DebugMode,
            onEnter = function()
                TriggerEvent('qb-garages:client:setHouseGarage', self.property_id, true)
            end,
        })
    end
end

function Property:UnregisterGarageZone()
    if not self.garageZone then return end
    if GetResourceState("ZSX_Garages") == "started" then return end

    TriggerEvent("qb-garages:client:removeHouseGarage", self.property_id)

    self.garageZone:remove()
    self.garageZone = nil
end

Last updated