Skip to content

Commit

Permalink
Optimizations + Stops spamming of GetPlayerData() constantly (Project…
Browse files Browse the repository at this point in the history
  • Loading branch information
JnKTechstuff authored Aug 3, 2023
1 parent 0595c5b commit d68ca86
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 20 deletions.
9 changes: 3 additions & 6 deletions client/cl_property.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ function Property:new(propertyData)
propertyData.furnitures = {}
self.propertyData = propertyData

local Player = QBCore.Functions.GetPlayerData()
local citizenid = Player.citizenid
local citizenid = PlayerData.citizenid

self.owner = propertyData.owner == citizenid
self.has_access = lib.table.contains(self.propertyData.has_access, citizenid)
Expand Down Expand Up @@ -632,8 +631,7 @@ end
function Property:UpdateOwner(newOwner)
self.propertyData.owner = newOwner

local Player = QBCore.Functions.GetPlayerData()
local citizenid = Player.citizenid
local citizenid = PlayerData.citizenid

self.owner = newOwner == citizenid

Expand Down Expand Up @@ -662,8 +660,7 @@ function Property:UpdateDoor(newDoor, newStreet, newRegion)
end

function Property:UpdateHas_access(newHas_access)
local Player = QBCore.Functions.GetPlayerData()
local citizenid = Player.citizenid
local citizenid = PlayerData.citizenid
self.propertyData.has_access = newHas_access
self.has_access = lib.table.contains(newHas_access, citizenid)

Expand Down
17 changes: 13 additions & 4 deletions client/client.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
QBCore = exports['qb-core']:GetCoreObject()
PlayerData = {}

local function createProperty(property)
PropertiesTable[property.property_id] = Property:new(property)
Expand All @@ -15,14 +16,18 @@ RegisterNetEvent('ps-housing:client:removeProperty', function (property_id)
PropertiesTable[property_id] = nil
end)

function InitialiseProperties()
function InitialiseProperties(properties)
Debug("Initialising properties")
PlayerData = QBCore.Functions.GetPlayerData()

for k, v in pairs(Config.Apartments) do
ApartmentsTable[k] = Apartment:new(v)
end

local properties = lib.callback.await('ps-housing:server:requestProperties')

if not properties then
properties = lib.callback.await('ps-housing:server:requestProperties')
end

for k, v in pairs(properties) do
createProperty(v.propertyData)
end
Expand All @@ -40,6 +45,10 @@ AddEventHandler("onResourceStart", function(resourceName) -- Used for when the r
end
end)

RegisterNetEvent('QBCore:Client:OnJobUpdate', function(job)
PlayerData.job = job
end)

RegisterNetEvent('ps-housing:client:setupSpawnUI', function(cData)
DoScreenFadeOut(1000)
local result = lib.callback.await('ps-housing:cb:GetOwnedApartment', source, cData.citizenid)
Expand Down Expand Up @@ -145,4 +154,4 @@ lib.callback.register('ps-housing:cb:showcase', function()
cancel = "Cancel"
}
})
end)
end)
2 changes: 1 addition & 1 deletion client/modeler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ Modeler = {
totalPrice = totalPrice + v.price
end

local PlayerData = QBCore.Functions.GetPlayerData()
PlayerData = QBCore.Functions.GetPlayerData()
if PlayerData.money.cash < totalPrice and PlayerData.money.bank < totalPrice then
Framework[Config.Notify].Notify("You don't have enough money!", "error")
return
Expand Down
11 changes: 10 additions & 1 deletion server/server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,15 @@ AddEventHandler("ps-housing:server:updateProperty", function(type, property_id,
property[type](property, data)
end)

AddEventHandler("onResourceStart", function(resourceName) -- Used for when the resource is restarted while in game
if (GetCurrentResourceName() == resourceName) then
while not dbloaded do
Wait(100)
end
TriggerClientEvent('ps-housing:client:initialiseProperties', -1, PropertiesTable)
end
end)

RegisterNetEvent("ps-housing:server:createNewApartment", function(aptLabel)
local src = source
if not Config.StartingApartment then return end
Expand Down Expand Up @@ -247,4 +256,4 @@ end
-- if PSCore then
-- PSCore.Functions.CheckForUpdates()
-- PSCore.Functions.CheckResourceName()
-- end
-- end
8 changes: 0 additions & 8 deletions shared/framework.lua
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ Framework.qb = {
icon = "fas fa-eye",
action = showcase,
canInteract = function()
local PlayerData = QBCore.Functions.GetPlayerData()
local job = PlayerData.job
local jobName = job.name
local onDuty = job.onduty
Expand All @@ -102,7 +101,6 @@ Framework.qb = {
icon = "fas fa-circle-info",
action = showData,
canInteract = function()
local PlayerData = QBCore.Functions.GetPlayerData()
local job = PlayerData.job
local jobName = job.name
local onDuty = job.onduty
Expand All @@ -123,7 +121,6 @@ Framework.qb = {
icon = "fas fa-building-shield",
action = raid,
canInteract = function()
local PlayerData = QBCore.Functions.GetPlayerData()
local job = PlayerData.job
local jobName = job.name
local gradeAllowed = tonumber(job.grade.level) >= Config.MinGradeToRaid
Expand Down Expand Up @@ -167,7 +164,6 @@ Framework.qb = {
action = seeAllToRaid,
icon = "fas fa-building-shield",
canInteract = function()
local PlayerData = QBCore.Functions.GetPlayerData()
local job = PlayerData.job
local jobName = job.name
local gradeAllowed = tonumber(job.grade.level) >= Config.MinGradeToRaid
Expand Down Expand Up @@ -318,7 +314,6 @@ Framework.ox = {
-- local property = Property.Get(property_id)
-- if property.propertyData.owner ~= nil then return false end -- if its owned, it cannot be showcased

local PlayerData = QBCore.Functions.GetPlayerData()
local job = PlayerData.job
local jobName = job.name

Expand All @@ -330,7 +325,6 @@ Framework.ox = {
icon = "fas fa-circle-info",
onSelect = showData,
canInteract = function()
local PlayerData = QBCore.Functions.GetPlayerData()
local job = PlayerData.job
local jobName = job.name
local onDuty = job.onduty
Expand All @@ -351,7 +345,6 @@ Framework.ox = {
icon = "fas fa-building-shield",
onSelect = raid,
canInteract = function()
local PlayerData = QBCore.Functions.GetPlayerData()
local job = PlayerData.job
local jobName = job.name
local gradeAllowed = tonumber(job.grade.level) >= Config.MinGradeToRaid
Expand Down Expand Up @@ -392,7 +385,6 @@ Framework.ox = {
onSelect = seeAllToRaid,
icon = "fas fa-building-shield",
canInteract = function()
local PlayerData = QBCore.Functions.GetPlayerData()
local job = PlayerData.job
local jobName = job.name
local gradeAllowed = tonumber(job.grade.level) >= Config.MinGradeToRaid
Expand Down

0 comments on commit d68ca86

Please sign in to comment.