From fe86ef5f56d9e7027ac82a792208be7d1f21fbd7 Mon Sep 17 00:00:00 2001 From: thelindat Date: Thu, 6 May 2021 19:42:56 +1000 Subject: [PATCH 1/2] Minor change to functions Add a TriggerEvent to `ESX.SetPlayerData` so we can tell other resources to update Only set networked vehicles as persistent and able to migrate Return entityCoords from `ESX.Game.GetVehicleInDirection` Only run `ServerSyncLoops` while ESX.PlayerLoaded is true Create an imports file to set ESX object and EventHandler for `esx:setPlayerData` --- client/functions.lua | 12 ++++++++---- client/main.lua | 4 ++-- fxmanifest.lua | 1 + imports.lua | 7 +++++++ 4 files changed, 18 insertions(+), 6 deletions(-) create mode 100644 imports.lua diff --git a/client/functions.lua b/client/functions.lua index 8d7df142..31df80fa 100644 --- a/client/functions.lua +++ b/client/functions.lua @@ -42,6 +42,7 @@ end ESX.SetPlayerData = function(key, val) ESX.PlayerData[key] = val + TriggerEvent('esx:setPlayerData', key, val) end ESX.ShowNotification = function(msg) @@ -365,10 +366,12 @@ ESX.Game.SpawnVehicle = function(model, coords, heading, cb, networked) ESX.Streaming.RequestModel(model) local vehicle = CreateVehicle(model, vector.xyz, heading, networked, false) - local id = NetworkGetNetworkIdFromEntity(vehicle) - SetNetworkIdCanMigrate(id, true) - SetEntityAsMissionEntity(vehicle, true, false) + if networked then + local id = NetworkGetNetworkIdFromEntity(vehicle) + SetNetworkIdCanMigrate(id, true) + SetEntityAsMissionEntity(vehicle, true, false) + end SetVehicleHasBeenOwnedByPlayer(vehicle, true) SetVehicleNeedsToBeHotwired(vehicle, false) SetModelAsNoLongerNeeded(model) @@ -494,7 +497,8 @@ ESX.Game.GetVehicleInDirection = function() local numRayHandle, hit, endCoords, surfaceNormal, entityHit = GetShapeTestResult(rayHandle) if hit == 1 and GetEntityType(entityHit) == 2 then - return entityHit + local entityCoords = GetEntityCoords(entityHit) + return entityHit, entityCoords end return nil diff --git a/client/main.lua b/client/main.lua index 751b5c33..73ed7844 100644 --- a/client/main.lua +++ b/client/main.lua @@ -352,7 +352,7 @@ end function StartServerSyncLoops() -- keep track of ammo Citizen.CreateThread(function() - while true do + while ESX.PlayerLoaded do Citizen.Wait(1000) local letSleep = true @@ -379,7 +379,7 @@ function StartServerSyncLoops() Citizen.CreateThread(function() local previousCoords = vector3(ESX.PlayerData.coords.x, ESX.PlayerData.coords.y, ESX.PlayerData.coords.z) - while true do + while ESX.PlayerLoaded do Citizen.Wait(1500) local playerPed = PlayerPedId() diff --git a/fxmanifest.lua b/fxmanifest.lua index 663669a4..f762a77f 100644 --- a/fxmanifest.lua +++ b/fxmanifest.lua @@ -73,6 +73,7 @@ ui_page { } files { + 'imports.lua', 'locale.js', 'html/ui.html', diff --git a/imports.lua b/imports.lua new file mode 100644 index 00000000..884eb4b5 --- /dev/null +++ b/imports.lua @@ -0,0 +1,7 @@ +ESX = exports['es_extended']:getSharedObject() + +AddEventHandler('esx:setPlayerData', function(key, val) + if GetInvokingResource() == 'es_extended' then + ESX.PlayerData[key] = val + end +end) \ No newline at end of file From 3d290354021cd4d6d77cd73539c0c0b960739183 Mon Sep 17 00:00:00 2001 From: Linden <65407488+thelindat@users.noreply.github.com> Date: Sun, 9 May 2021 01:04:11 +1000 Subject: [PATCH 2/2] Set account data too --- client/main.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/client/main.lua b/client/main.lua index 73ed7844..2fa7d567 100644 --- a/client/main.lua +++ b/client/main.lua @@ -121,6 +121,7 @@ AddEventHandler('esx:setAccountMoney', function(account) break end end + ESX.SetPlayerData('accounts', ESX.PlayerData.accounts) if Config.EnableHud then ESX.UI.HUD.UpdateElement('account_' .. account.name, {