Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for multiple issues #156

Merged
merged 4 commits into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions client/cl_property.lua
Original file line number Diff line number Diff line change
Expand Up @@ -534,9 +534,12 @@ function Property:RemoveBlip()
end

function Property:RemoveProperty()
local targetName = string.format("%s_%s", self.propertyData.street, self.property_id)

Framework[Config.Target].RemoveTargetZone(targetName)
if Config.Target == "ox" then
Framework[Config.Target].RemoveTargetZone(self.entranceTarget)
else
local targetName = string.format("%s_%s", self.propertyData.street, self.property_id)
Framework[Config.Target].RemoveTargetZone(targetName)
end

self:RemoveBlip()

Expand Down
51 changes: 47 additions & 4 deletions server/server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ lib.callback.register("ps-housing:server:requestProperties", function(source)
return PropertiesTable
end)

AddEventHandler("ps-housing:server:registerProperty", function (propertyData) -- triggered by realtor job
AddEventHandler("ps-housing:server:registerProperty", function (propertyData, preventEnter) -- triggered by realtor job
local propertyData = propertyData

propertyData.owner = propertyData.owner or nil
Expand Down Expand Up @@ -75,7 +75,7 @@ AddEventHandler("ps-housing:server:registerProperty", function (propertyData) --

TriggerClientEvent("ps-housing:client:addProperty", -1, propertyData)

if propertyData.apartment then
if propertyData.apartment and not preventEnter then
local player = QBCore.Functions.GetPlayerByCitizenId(propertyData.owner)
local src = player.PlayerData.source

Expand Down Expand Up @@ -138,8 +138,8 @@ end)

RegisterNetEvent("ps-housing:server:createNewApartment", function(aptLabel)
local src = source
if not Config.StartingApartment then return end
local citizenid = GetCitizenid(src)
if not Config.StartingApartment then return end
local PlayerData = GetPlayerData(src)

local apartment = Config.Apartments[aptLabel]
Expand All @@ -160,6 +160,23 @@ RegisterNetEvent("ps-housing:server:createNewApartment", function(aptLabel)
TriggerEvent("ps-housing:server:registerProperty", propertyData)
end)

-- we show the character creator if they spawn without starting appartment and doesn't have skin set
RegisterNetEvent("QBCore:Server:OnPlayerLoaded", function()
if Config.StartingApartment then return end

local src = source
local citizenid = GetCitizenid(src)
local query = "SELECT skin FROM playerskins WHERE citizenid = ?"
local result = MySQL.Sync.fetchAll(query, {citizenid})

if result and result[1] then
Debug("Player: " .. citizenid .. " skin already exists!")
else
TriggerClientEvent("qb-clothes:client:CreateFirstCharacter", src)
Debug("Player: " .. citizenid .. " is creating a new character!")
end
end)

-- Creates apartment stash
-- If player has an existing apartment from qb-apartments, it will transfer the items over to the new apartment stash
RegisterNetEvent("ps-housing:server:createApartmentStash", function(citizenId, propertyId)
Expand Down Expand Up @@ -202,13 +219,39 @@ AddEventHandler("ps-housing:server:addTenantToApartment", function (data)
Framework[Config.Notify].Notify(targetSrc, "This person is already in this apartment", "error")

return
elseif #propertyData.apartment > 1 then
elseif propertyData.apartment and #propertyData.apartment > 1 then
property_id = propertyData.property_id
break
end
end
end

if property_id == nil then
local newApartment = Config.Apartments[apartment]
if not newApartment then return end

local citizenid = GetCitizenid(targetSrc, realtorSrc)
local targetToAdd = QBCore.Functions.GetPlayerByCitizenId(citizenid).PlayerData
local propertyData = {
owner = targetCitizenid,
description = string.format("This is %s's apartment in %s", targetToAdd.charinfo.firstname .. " " .. targetToAdd.charinfo.lastname, apartment.label),
for_sale = 0,
shell = newApartment.shell,
apartment = newApartment.label,
}

Debug("Creating new apartment for " .. GetPlayerName(targetSrc) .. " in " .. newApartment.label)

Framework[Config.Logs].SendLog("Creating new apartment for " .. GetPlayerName(targetSrc) .. " in " .. newApartment.label)

Framework[Config.Notify].Notify(targetSrc, "Your apartment is now at "..apartment, "success")
Framework[Config.Notify].Notify(realtorSrc, "You have added ".. targetToAdd.charinfo.firstname .. " " .. targetToAdd.charinfo.lastname .. " to apartment "..apartment, "success")

TriggerEvent("ps-housing:server:registerProperty", propertyData, true)

return
end

local property = Property.Get(property_id)
if not property then return end

Expand Down
2 changes: 1 addition & 1 deletion server/sv_property.lua
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ function Property:UpdateGarage(data)
["@property_id"] = self.property_id
})

TriggerClientEvent("ps-housing:client:updateProperty", -1, "UpdateGarage", self.property_id, garage)
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))

Expand Down
3 changes: 3 additions & 0 deletions shared/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ Config.Commissions = {
-- Set this value to false if you don't want to assign a starting apartment.
Config.StartingApartment = true

--- With this enabled, the customizer will open when starting apartment is false.
Config.ShowCustomizerWhenNoStartingApartment = true

Config.Apartments = {
["Integrity Way"] = {
label = "Integrity Way",
Expand Down