diff --git a/README.md b/README.md index 6a08124e..37449fa6 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ git clone https://github.com/ESX-Org/esx_property [esx]/esx_property ## Installation - Import `esx_property.sql` in your database -- Import `esx_offices.sql` in your database if you want the offices to added in your server (The Arcadius Business Centre is not included because realstateagentjob) +- Import `esx_offices.sql` in your database if you want offices (The Arcadius Business Centre is not included because realstateagentjob) - Add this to your `server.cfg`: ``` diff --git a/__resource.lua b/__resource.lua index bbfc1bf1..1ace3383 100644 --- a/__resource.lua +++ b/__resource.lua @@ -33,5 +33,9 @@ client_scripts { dependencies { 'es_extended', - 'instance' + 'instance', + 'cron', + 'esx_addonaccount', + 'esx_addoninventory', + 'esx_datastore' } diff --git a/client/main.lua b/client/main.lua index e676adb6..850d24d0 100644 --- a/client/main.lua +++ b/client/main.lua @@ -31,6 +31,21 @@ Citizen.CreateThread(function() end end) +RegisterNetEvent('esx:playerLoaded') +AddEventHandler('esx:playerLoaded', function(xPlayer) + ESX.TriggerServerCallback('esx_property:getProperties', function(properties) + Config.Properties = properties + CreateBlips() + end) + + ESX.TriggerServerCallback('esx_property:getOwnedProperties', function(ownedProperties) + for i=1, #ownedProperties, 1 do + SetPropertyOwned(ownedProperties[i], true) + end + end) +end) + +-- only used when script is restarting mid-session RegisterNetEvent('esx_property:sendProperties') AddEventHandler('esx_property:sendProperties', function(properties) Config.Properties = properties @@ -854,26 +869,25 @@ AddEventHandler('instance:loaded', function() end) AddEventHandler('playerSpawned', function() + if FirstSpawn then - if FirstSpawn then + Citizen.CreateThread(function() - Citizen.CreateThread(function() + while not ESX.IsPlayerLoaded() do + Citizen.Wait(0) + end - while not ESX.IsPlayerLoaded() do - Citizen.Wait(0) - end - - ESX.TriggerServerCallback('esx_property:getLastProperty', function(propertyName) - if propertyName ~= nil then - TriggerEvent('instance:create', 'property', {property = propertyName, owner = ESX.GetPlayerData().identifier}) - end - end) - - end) - - FirstSpawn = false - end + ESX.TriggerServerCallback('esx_property:getLastProperty', function(propertyName) + if propertyName ~= nil then + if propertyName ~= '' then + TriggerEvent('instance:create', 'property', {property = propertyName, owner = ESX.GetPlayerData().identifier}) + end + end + end) + end) + FirstSpawn = false + end end) AddEventHandler('esx_property:getProperties', function(cb) @@ -904,7 +918,6 @@ end) RegisterNetEvent('instance:onEnter') AddEventHandler('instance:onEnter', function(instance) - if instance.type == 'property' then local property = GetProperty(instance.data.property) diff --git a/server/main.lua b/server/main.lua index 14a6ba1e..6e2e136e 100644 --- a/server/main.lua +++ b/server/main.lua @@ -159,12 +159,16 @@ function LoadSql() roomMenu = roomMenu, price = properties[i].price }) - end - - TriggerClientEvent('esx_property:broadcastProperties', -1, Config.Properties) + end + + TriggerClientEvent('esx_property:sendProperties', -1, Config.Properties) end) end +ESX.RegisterServerCallback('esx_property:getProperties', function(source, cb) + cb(Config.Properties) +end) + AddEventHandler('esx_ownedproperty:getOwnedProperties', function(cb) MySQL.Async.fetchAll(