Skip to content

Commit

Permalink
Fixes for multiple issues (Project-Sloth#156)
Browse files Browse the repository at this point in the history
* fix(Project-Sloth#140): Should fix target zone not getting removed when using OX

* Fix(Project-Sloth#48): Garage location should now update after moving it

* Fix(Project-Sloth#121): Should now show character creation even if not using starter apparments

* fix(Project-Sloth#154): Should now be able to assign appartments when not having one already
  • Loading branch information
Walter-00 authored Nov 27, 2023
1 parent 0945703 commit 675dea1
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 8 deletions.
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

0 comments on commit 675dea1

Please sign in to comment.